There are a few perils unique to developing Windows Services in .NET. This is one of them.
The other day, I renamed some of my subversion working folders. Unfortunately, one of the folders that I renamed actually included a service that I had registered via installutil.exe on my local machine.
There is a problem with installutil.exe which means that this could be an unrecoverable Catch-22 situation. Here's why:
The other day, I renamed some of my subversion working folders. Unfortunately, one of the folders that I renamed actually included a service that I had registered via installutil.exe on my local machine.
There is a problem with installutil.exe which means that this could be an unrecoverable Catch-22 situation. Here's why:
- You cannot uninstall it. If you try to uninstall it with installutil /u and point to your service (e.g. "uninstall /u DDK.ProjectName.MyNotificationServiceName", it cannot find the file will and give a "Exception occurred while initializing the installation: System.IO.FileNotFoundException: Could not load file or assembly '[Full Path To My File]' or one of its dependencies. The system cannot find the file specified.."
- You cannot install the exe to a different location with installutil because the service is already installed. If you do try to install it with a new path, you will just get the error "An exception occurred during the Install phase.System.ComponentModel.Win32Exception: The specified service already exists".
So to install a service with the same at the new location, I would have to:
- Copy the old file back to the original Windows Service Location location (or restore it from a backup) and run installutil /u on it. If I don't have the file anymore, I would not be able to do this.
- OR Remove the registry entry for the service.
This would not be as much of an issue if installutil /u recognized the missing service and prompted me if I wanted to remove the registry entry - but it didn't. I understand you want to do cleanup of a service when an uninstall is called - but you shouldn't be left in an unrecoverable state because of a lack of functionality in the core installer utility.
So when you don't have access to the file/drive you originally installed a service to, you can fix this unrecoverable (from the perspective of installutil) situation by either:
So when you don't have access to the file/drive you originally installed a service to, you can fix this unrecoverable (from the perspective of installutil) situation by either:
- Opening regedit
- Going to HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services
- Removing the old registry entry for your service.
OR
Running "sc" from a command prompt - see screenshot below for parameters:
7 comments:
Thanks for the info! I installed a custom vb.NET service successfully using "InstallUtil.exe". When I attempted to uninstall the service with "InstallUtil.exe", I received the "Windows could find the specified file" error even though I never changed the path or filename. Anyway, the "sc" utility worked great!
Hi David, this is the second time that you saved me a lot of time.
Thank you very much!
PS: Send a hello from Brazil to AG for me :)
Hi,David,thank you very much.I installed VB.NET Service successfully using "InstallUtil.exe",by the way,I am come from China,and I know you been to the Great Wall,so did I.
I just ran into this problem myself, and it turns out that uninstall will work if you run it from the new directory where your service is. If it can find the .exe file in the current directory, it will uninstall the service. It doesn't have to be in the original location.
This solution to remove windows services works perfectly. Thank You.
Tx David and Mike worked like a charm!
Tx David and Mike worked like a charm!
Post a Comment