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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With