卸载 Windows 服务有时会失败并强制重新启动计算机

发布于 2024-10-03 05:57:21 字数 320 浏览 5 评论 0原文

我在卸载和重新安装 Windows 服务时遇到问题。有时,当我使用服务的 MSI 包进行卸载时(即使在停止服务并关闭服务管理控制台之后),该服务也不会被卸载,然后如果我运行“installUtil”,则该服务将被禁用,但不会被删除从控制台。然后,如果我尝试“sc delete service.exe”,则会收到错误“服务已标记为删除”。一旦发生此错误,我唯一的选择就是重新启动工作站或服务器(无论其安装在何处)。有时它工作正常,有时却无法正确卸载。如何确保卸载始终有效?为什么卸载这么痛苦?在开发过程中,我需要多次重新安装服务来安装新版本的服务,并且无需重新启动计算机即可轻松重新安装服务,这将很有用。
提前致谢。

I am having trouble with uninstallation and reinstallation of windows service. sometimes when I uninstall using the MSI package for the service (even after stopping the service and closing the service management console), the service is not getting uninstalled and then if I run "installUtil", then the service is getting disabled, but not removed from the console. then if I try "sc delete service.exe", I get an error "service is marked for deletion". once this error occurs, the only option I have is to restart the workstation or the server wherever it is installed. sometimes it works fine and sometimes it doesn't uninstall properly. how can I ensure that the uninstall works always? why uninstall is so painful? during development, I need to reinstall the service several times to install new version of the service and it will be useful to easily reinstall the service without having to restart the machine.

thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柒夜笙歌凉 2024-10-10 05:57:22

也许您的服务在关闭时遇到一些问题,因为它遇到了未处理的错误。如果有日志,请尝试查看那里是否没有抛出任何内容。否则,我会添加一个日志机制(例如log4net)。如果添加日志记录机制不是一个选择,chezy525 的解决方案似乎是可行的方法。

Maybe your service is having some problem shutting down because it is suffering from an unhandled error. If there is a log, try to see if nothing is thrown there. Otherwise, I would add a log mechanism (log4net for example). If adding a logging mechanism is not an option, chezy525's solution seems the way to go.

倥絔 2024-10-10 05:57:21

当我在测试过程中不断安装、重建和卸载服务时,我遇到了类似的问题。我认为这与尝试卸载服务之前重建 MSI 有关。始终从“添加/删除程序”对话框卸载应该可以避免这种情况,但这有点麻烦。我最终修改了 Wix 设置项目以执行三件事:

  1. 设置 MSI 来启动/停止服务。 此处有一个示例。
  2. 如果已安装当前版本或新版本,则可以执行自定义操作来停止安装。基于代码。
  3. 在桌面上创建卸载快捷方式。一个示例 这里

I ran into a similar problem when I was constantly installing, rebuilding, and uninstalling my service during testing. I think it had to do with rebuilding the MSI before trying to uninstall the service. Always uninstalling from the Add/Remove programs dialog should avoid this, but it's a bit of a hassle. I ended up modifying my Wix setup project to do three things:

  1. The MSI is setup to start/stop the service. One example here.
  2. Have a custom action to stop the install if the current version or a new version is already installed. Based on this code.
  3. Create an uninstall shortcut on the desktop. One example here.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文