views:

472

answers:

2

We install a windows service from a custom action as described here: CodeProject

Every so often, when uninstalling our application, it does not properly uninstall the service. Instead it "marks the service for deletion".

You can see this message by running installutil.exe /u on our executable, when it is supposedly uninstalled.

Has anyone seen this issue or know a workaround? If a service is somehow installed with the same name as ours, we'd like to replace it. Instead the msi setup fails, giving a message saying our service is already installed.

Is there a way to do it without making a custom action to first uninstall any existing instances of our service's name before running the install custom action?

+2  A: 

Is the service control panel (services.msc) open while you uninstall? This prevents your service from correctly being uninstalled.

If nothing else helps a reboot might be required as recommended in this article (though originally applying to .NET 1.1).

0xA3
We might just prompt for a restart on uninstall. This seems like a good solution. I'll mark you as the answer in a day or two, if no one has a better solution.
Jonathan.Peppers
I hope you find a better solution than rebooting. Have you checked with Process Explorer that the service process is no longer running? If it is still running you can further investigate the process with Process Explorer (see running threads, open handles, loaded dlls).
0xA3
When in this state, our process is no longer running and our MSI has removed the executable from the file system. However, our service is still listed in services.msc and if you run the "net start" command. It is sadly, very difficult to reproduce and I don't think it happens every time you have services.msc open on uninstall. Rebooting seems like the only thing that will truly fix it, windows is waiting for the PC to restart before deleting the service.
Jonathan.Peppers
Could it be that the service console is open in another session like this guy had? http://weblogs.asp.net/avnerk/archive/2007/09/05/windows-services-services-msc-and-the-quot-this-service-is-marked-for-deletion-quot-error.aspx
0xA3
I think you're right, good link. We're going to have our setup prompt the user to close mmc.exe, like other setups do for IE, etc.
Jonathan.Peppers
A: 

Check, if your service correctly stops additional thread(s) started from the service.

den123
All our threads are ThreadPool threads, so this should not be an issue.
Jonathan.Peppers