How to force uninstallation of windows service

Viewed 199188

I installed a windows service using installUtil.exe.

After updating the code I used installUtil.exe again to install the service w/o uninstalling the original version first.

When I now try to uninstall the service, installUtil.exe completes the uninstall successfully, but the service still appears.

If I try to change its properties, I receive the message 'service is marked for deletion'.

How can I force the deletion (preferrably w/o restarting the server)?

20 Answers
sc delete sericeName

Just make sure the service is stopped before doing this. I have seen this work most times. There are times where I have seen windows get stuck on something and it insists on a reboot.

It is also worth noting that this:

sc delete "ServiceName"

does not work in PowerShell, sc is an alias for the cmdlet Set-Content in PowerShell. You need to do:

sc.exe delete "ServiceName"

Unfortunately, you need to restart the server. That should remove the "deleted" service.

This worked for me:

net stop "MyWindowsService"
taskkill /F /IM mmc.exe
sc delete "MyWindowsService"

The following will work without restarting the machine:

  1. Search the Registry \ HKEY_LOCAL_MACHINE for < Your Service Name > (both keys and values)
  2. Set "Legacy" value to 0

Have you try stopping the service before calling uninstall? I had this problem randomly. Sometime I could remove it without restarting. My guess is that it has to do with the service still running

If you can not stop the service in Services, you can stop your windows service exe in Task Manager. After that, you can remove the service.

Related