windows service uninstallation

464 views Asked by At

I created a simple windows service. And added setup project to this solution. I could build service and setup project successfully. Also after build I could use the MSI file created successfully. I could install windows service successfully and could achiev the functionality.

But now I want to uninstall the service and from Add/Remove programs I am removing this service. The service is uninstalled from Add/Remove programs. But still I can see the service in the list of Service. Do I need to add anything while creating the setup for windows service?

2

There are 2 answers

4
Koby Douek On BEST ANSWER

When you create a setup project you can set external commands to run before installation:

  1. Right click the SetupProject from visual studio and select "custom actions" from the view.
  2. You will find these custom actions: install, commit, rollback and uninstall.
  3. Right click on each of these actions one after the other and add a custom action.
  4. After doing so you will find a select item in project window.
  5. In the window, select Application folder in the dropdown. This will list the primary output from windows service, select it and click ok.
  6. Save and build the setup project.
0
PhilDW On

The typical problem when uninstalling services with the service installer classes is that setup projects provide no automatic stopping of the service. So the uninstall marks the service for removal. It can't remove it because it doesn't stop it. If you reboot the system you might see the service finally disappear.

The typical solution is to override the Uninstall custom action and add your own code to explicitly stop the service, then base.Uninstall() will be able to remove it.

An even better solution is to use another tool that has support for the built-in Windows Installer functionality that just does this without any code (ServiceInstall and ServiceControl tables).