Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why windows installer doesn't remove service?

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?

like image 287
RJN Avatar asked Feb 16 '26 05:02

RJN


1 Answers

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.

like image 190
RJN Avatar answered Feb 17 '26 18:02

RJN