Wednesday, April 7, 2010

Uninstalling a .NET service

Hello World,

Well, this should be pretty simple: InstallUtil.exe is provided with the .NET framework for manual install/uninstall as described here: MSDN Link

Basically what I like to do when running a command like this is to add it to the "Path" variable under my environment variables.
For example, if you are working with .NET framework 3.5, on a Windows server 2003 (32-bit Standard edition), InstallUtil.exe can be found at the following path:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

So, to be able to launch the utility without having to type the entire path, add the path (in italics above, based on your system configuration) to your "Path" environment variable.
For instructions on how to edit your environment variables, refer THIS link. Once done, to install a .NET service, open up a command prompt (Start -> Run -> cmd) and
browse to the path of your service executable. e.g. C:\Projects\MyWinService\MyWinService.exe and issue the command InstallUtil MyWinService.exe

What I managed to do (don't ask me why!) is delete the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyWinService. After that all my attempts to uninstall the service were unsuccessful. Needless to mention, the service could not be installed again as Windows complained that "The service is already installed"
Then, I thought, let me try this: from a backup, I copied over the service executable to the folder where it should have been. Then, I issued the command
InstallUtil /u MyWinService.exe
[/u uninstalls the service]

and, as expected, the utility successfully un-installed the service!

[By the way, for .NET services, the old style -service command does not install them to the service controller. Neither does /uninstall remove them.]

Best Of luck!

No comments:

Post a Comment