Dec 15, 2008

Cannot Uninstall / Install Windows Service App

Project: A windows Service and a Windows Service Installer Project.
Problem: When after some code changes I tried to uninstall the Windows service, I got the following error message
"An exception occurred while uninstalling. This exception will be ignored and the uninstall will continue. however, the application might not be fully uninstalled after the uninstall is complete.--> The specified service does not exist as an installed service"

Cause: From the internet I came to know that it could be for various reasons.
1. Somewhere along the way, I might have a ServiceInstaller object. and gave the ServiceInstaller a name which looks like this: serviceInstaller1.ServiceName = "Hello-World Service 1";
When you renamed your service in Windows Explorer, you did not rename theServiceName in the code. The system is attempting to overwrite the sameservice.Rename this value as well.

2. Make sure your install and uninstall code is 100% (not 99.999995%) exception proof. If an exception is thrown during the install or uninstall process your system may be left in a permanently unstable position [twice in the last three years I had to do a complete wipe and re-format to properly cleanup a service that had thrown an exception.....
3. I didn't stop my service before uninstalling it and things got ugly.
Solution:
Links: 1. http://hardware.mcse.ms/archive97-2005-7-159894.html
2. http://social.microsoft.com/Forums/en-US/netfxbcl/thread/cdd24c4c-ad3e-4704-ae5e-7749cdae7521

1. Open the CPrompt
2. Move to the folder containing the msi file

3. invoke msiexec /fv install_filename.msi
where install_filename is the name of your msi install file.
/fv - is a repair option that tells the installer to "run from source and recache locl package"
for a list of all the msiexec commands just type in msiexec at the command prompt.