views:

10787

answers:

10

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?

+8  A: 

Are you not able to stop the service before the update (and restart after the update) using the commands below?

net stop <service name>
net start <service name>

Whenever I'm testing/deploying a service I'm able to upload files without reinstalling as long as the service is stopped. I'm not sure if the issue you are having is different.

Jonathan S.
This has always been my experience - I have endlessly updated services merely by stopping them and replacing the .EXE. It's only an ordinary process anyway.
Will Dean
+1  A: 

If in .net ( I'm not sure if it works for all windows services)

  • Stop the service (THis may be why you're having a problem.)
  • InstallUtil -u [name of executable]
  • Installutil -i [name of executable]
  • Start the service again...

Unless I'm changing the service's public interface, I often deploy upgraded versions of my services without even unistalling/reinstalling... ALl I do is stop the service, replace the files and restart the service again...

Charles Bretana
+1  A: 

Both Jonathan and Charles are right... you've got to stop the service first, then uninstall/reinstall. Combining their two answers makes the perfect batch file or PowerShell script.

I will make mention of a caution learned the hard way -- Windows 2000 Server (possibly the client OS as well) will require a reboot before the reinstall no matter what. There must be a registry key that is not fully cleared until the box is rebooted. Windows Server 2003, Windows XP and later OS versions do not suffer that pain.

Mike L
A: 

(so Windows releases it's hold on the file)

Instead, do Ctrl+Alt+Del right after the Stop of the service and kill the .exe of the service. Than, you can uninstall the service without rebooting. This happened to me in the past and it solves the part that you need to reboot.

Daok
+6  A: 

sc /delete "service name"

will stop and delete a service. I find that the sc utility is much easier to locate than digging around for installutil.

StingyJack
sc delete "service name" < at least on windows 7.
Esben Skov Pedersen
A: 

Dealing with locked files in general, I've gotten good usage out of "unlocker": http://ccollomb.free.fr/unlocker/

Joeri Sebrechts
A: 

brilliant!!! sc worked in notime!!! thanks stingyjack...

A: 

As noted by StingyJack and mcbala, and in reference to comments made by Mike L, my experience is that on a Windows 2000 machine, when uninstalling / reinstalling .Net services, "installutil /u" does require a reboot, even when the service was previously stopped. "sc /delete", on the other hand, does not require a reboot - it deletes the service right away (as long as it is stopped).

I have often wondered, actually, whether there is a good reason "installutil /u" requires a reboot... Is "sc /delete" actually doing something wrong / leaving something hanging?

Tao
A: 

Try to use.... ' sc delete "My_service" ' it should work. it is working for me dude.

A: 

Should it be necessary to manually remove a service:

  1. Run Regedit or regedt32.
  2. Find the registry key entry for your service under the following key: HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services
  3. Delete the Registry Key

You will have to reboot before the list gets updated in services

chrishawn