How to uninstall Windows service using Custom Uninstaller
We have many questions on stackoverflow regarding uninstallation of Windows Service.
After trying all of them I still fail to uninstall the windows service on new version Installation.I use setup and deployment project to install/uninstall 开发者_JAVA技巧my project which has a windows service and some other projects.
During installation of newer version, all other projects are successfully re-installed but windows service project fails to Re-install and says:
Error 1001: The specified service already exists.
I referred this link and tried to add code to my Install custom action to Stop the service. If I understood the answer in this link correctly, I have put the code to stop the service inside projectInstaller.cs file of the Service:
public override void Install(IDictionary stateSaver)
{
ServiceController sc = new ServiceController("SareeManagerNotifications");
if (sc.Status == ServiceControllerStatus.Running)
sc.Stop();
base.Install(stateSaver);
}
Custom action pane looks like:
Where the highlighted part is the Service.
I also went through this answer which says to set custom action condition as
NOT PREVIOUSVERSIONSINSTALLED
.
This doesn't work for me. Where am I going wrong ?
Thanks in advance :)
Try the following steps while editing the windows service:
Right click your SetupProject from visual studio and select custom actions from view.
You will find 4 custom actions install,commit,rollback and uninstall. Right click on each of these actions one after the other and add a custom action
After doing so you will find a select item in project window. In the window select Application folder from look in dropdown. This will list the primary output from windows service, select this and click ok.
Save and build the setup project.
Hope this will solve your issue....
Usually this is done through service control operations. Basically, you need the Stop and Delete flags set for uninstall.
Another approach would be to use ServiceInstaller.Uninstall to remove the service.
精彩评论