Reputation: 736
I have created windows service project (WinService.exe) using C#. Also I added installer capability with the project(ProjectInstaller.cs) as per the below guide from Microsoft: https://learn.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer
Now, when I performed install and uninstall using installutil.exe, my windows service project adds the service into services panel and removes from it appropriately.
As I want to deploy this service into remote machine, I created windows installer project(DeployService.msi) using VisualStudio 2015 as a service deployment project. Also, I configured custom action for Install, UnInstall, Commit and Rollback targeting primary output as WinService project.
When I perform installation using this installer, the service gets added into services panel and ApplicationFolder copies all binaries required for service. But, when I perform uninstall, ApplicationFolder binaries are removed but it leaves a InstallState file i.e WinService.InstallState. IMPORTANTLY, the service is not removed from services panel.
Any help here to remove service from services panel via windows installer?
Upvotes: 3
Views: 2230
Reputation: 736
I have tried adding event handler for ServiceProcessInstaller and noticed that OnBeforeUninstall() and OnAfterUinstall() are never called by windows installer due to some reason. At same time, I noticed OnBeforeInstall() and OnAfterInstall() are called. This is main reason why windows service was not uninstalled in my case.
When I tried overriding ProjectInstaller (derviced from Installer) class methods:
protected override void OnBeforeUninstall(IDictionary savedState);
protected override void OnAfterUninstall(IDictionary savedState);
I observed windows installer calls these methods appropriately and I have written appropriate methods to remove windows service there.
Upvotes: 2
Reputation: 273
You can try to execute the next command when you execute the uninstall of the application, which removes the service with the exact name (you can try it using the CMD):
sc delete “serviceName”
Upvotes: 0