简体   繁体   中英

Removing/installing a Windows Service

I've created a Windows Service project in C#, just some very simple code. It worked when i installed the service, but now I have to add some code and so on,but that has caused some issues:

1) When trying to uninstall using "installutil /u" it says its removed however its still on the service list in computeradministration.

1a) I tried to delete it with cmd using "sc delete ServiceName" which removes it from the list

2) BUT when i install the new build it succeeds, however it still uses the old build for some reason, and im kindda at a loss.

You only have to install once. The service will be registered with the .exe you registered using sc or installutil .

To replace the binary, just stop the service, replace the binary with the "new" one and restart: the new service will be running.

Also, you have to restart services.msc to see that some services are removed (there seems to be some "pending removal" flag).

If your service is in use (eg it is running) when you uninstall it you may have to restart your computer after uninstalling it before it is completely uninstalled. installutil and sc does not give you any information about this. And when a service is pending removal you can get into all sorts of problems if you try to install it again (which seems to the problem that you experience).

Make sure that the service is stopped before uninstalling it to avoid having to restart your computer to complete the uninstall.

If you just want to update the binary of the service you can simply stop it and replace the executable files before restarting the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM