1

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?

sp4stack
  • 13
  • 5

2 Answers2

0

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.
Koby Douek
  • 16,156
  • 19
  • 74
  • 103
  • Yes but that is the task I have to do it externally. When I am uninstalling the service it should completely uninstall the service. Is there anything that I can implement in the setup project. – sp4stack Aug 23 '17 at 13:46
  • Thanks Koby. This resolved my issue. So marking it as answer. But while clicking on Ok for primary output the alert came as 'Operation could not be completed. Exception occured' – sp4stack Aug 24 '17 at 09:14
  • Does it give any more details? Where is the exception coming from? – Koby Douek Aug 24 '17 at 09:16
  • In your 5th step, when I click Ok button I get the alert. But it comes sometimes not everytime. So when it did not come got added in the left panel for repsective actions. And I could say it works now. – sp4stack Aug 24 '17 at 09:48
0

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).

PhilDW
  • 20,260
  • 1
  • 18
  • 28