How to uninstall a windows service and delete its files without rebooting

Nate Sauber picture Nate Sauber · Nov 18, 2008 · Viewed 111.1k times · Source

My current project involves deploying an upgraded .exe file that runs as a Windows Service. In order to overwrite the existing .exe with the new version, I currently need to:

  1. Stop the service
  2. Uninstall the service
  3. Reboot the system (so Windows releases it's hold on the file)
  4. Deploy the new .exe
  5. Reinstall the service
  6. Start the upgraded service.

I'd like to avoid the reboot, so that this can be a fully scripted/automated upgrade.

Is there any way to avoid rebooting? Maybe a command-line tool that will force Windows to give up it's death grip on the old .exe?

Answer

StingyJack picture StingyJack · Nov 19, 2008
sc delete "service name"

will delete a service. I find that the sc utility is much easier to locate than digging around for installutil. Remember to stop the service if you have not already.