卸载 Windows 服务有时会失败并强制重新启动计算机
我在卸载和重新安装 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您的服务在关闭时遇到一些问题,因为它遇到了未处理的错误。如果有日志,请尝试查看那里是否没有抛出任何内容。否则,我会添加一个日志机制(例如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.
当我在测试过程中不断安装、重建和卸载服务时,我遇到了类似的问题。我认为这与尝试卸载服务之前重建 MSI 有关。始终从“添加/删除程序”对话框卸载应该可以避免这种情况,但这有点麻烦。我最终修改了 Wix 设置项目以执行三件事:
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: