0

I delete a windows service with a sc.exe delete <serviceName>.

Immediately after that, I delete the files owned by the service (an exe and a couple of dlls) and I cannot because these files are still locked.

I've found out that it works if I execute a sleep of 3 seconds (I wonder what is Windows doing for 3 seconds!) between the service delete and the files delete.

Is there some more elegant and secure solution?

Probably useless detail: I'm running this from Inno Setup on Jenkins on Windows 7

marco
  • 1,686
  • 1
  • 25
  • 33

1 Answers1

0

Initially, you can kill the process(es) of that services to release the resources it has by typing these commands;

> $ServicePID = (get-wmiobject win32_service | where { $_.name -eq 'service name'}).processID
> Stop-Process $ServicePID -Force

Then, you can delete that service by typing as you can indicate:

> sc.exe delete <serviceName>