Frage

I have C# service that uses FileSystemWatcher and invokes associated commands (e.g. batch files). One of the batch files needs to kill a running program, copy some files and start the program again. Taskkill is used to get rid of the program.

The batch file gets called, but taskkill command never kills a process (e.g. notepad.exe that a user has open). The same batch file works if i just run it when im logged in as that user.

I tried running the service as the logged on user account (the same one that has notepad open) to no avail - the default is Local System.

I can't hardcode the username (i am thinking, however, of configuration for impersonation but a bit reluctant to store the users' passwords).

Any suggestions?

War es hilfreich?

Lösung

running as local service always has the highest privilege, try taskkill /f to force terminate it. however, if still fail, check the error code by %errorlevel%

Andere Tipps

Perhaps, it is worth deleting, perhaps not. The local system was able to kill the process with the /F (force) switch on the taskkill.exe

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top