如何使用自定义卸载程序卸载 Windows 服务
我们在 stackoverflow 上有很多关于卸载 Windows 服务的问题。
在尝试了所有这些方法后,我仍然无法在新版本安装中卸载 Windows 服务。
我使用安装和部署项目来安装/卸载我的项目,该项目有一个 Windows 服务和一些其他项目。
在安装新版本期间,所有其他项目均已成功重新安装,但 Windows 服务项目无法重新安装并显示:
错误1001:指定的服务已存在。
我提到此链接 并尝试将代码添加到我的安装自定义操作中以停止服务。如果我正确理解了此链接中的答案,我已将代码放入服务的 projectInstaller.cs 文件中停止服务:
public override void Install(IDictionary stateSaver)
{
ServiceController sc = new ServiceController("SareeManagerNotifications");
if (sc.Status == ServiceControllerStatus.Running)
sc.Stop();
base.Install(stateSaver);
}
自定义操作窗格如下所示:
其中突出显示的部分是服务。
我还经历了这个答案表示将自定义操作条件设置为NOT PREVIOUSVERSIONSINSTALLED
。
这对我不起作用。我哪里出错了?
提前致谢 :)
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 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 asNOT PREVIOUSVERSIONSINSTALLED
.
This doesn't work for me. Where am I going wrong ?
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑 Windows 服务时尝试以下步骤:
右键单击 Visual Studio 中的 SetupProject,然后从视图中选择自定义操作。
您会发现 4 个自定义操作安装、提交、回滚和卸载。依次右键单击这些操作,然后添加自定义操作
执行此操作后,您将在项目中找到一个选择项窗口。在窗口中,从查找下拉列表中选择应用程序文件夹。这将列出Windows 服务的主要输出,选择此项并单击“确定”。
保存并构建安装项目。
希望这能解决您的问题......
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....
通常这是通过服务控制操作完成的。基本上,您需要设置停止和删除标志才能卸载。
另一种方法是使用 ServiceInstaller.Uninstall删除该服务。
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.