.net 如何强制卸载windows服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/225275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to force uninstallation of windows service
提问by Manu
I installed a windows service using installUtil.exe.
我使用 installUtil.exe 安装了 Windows 服务。
After updating the code I used installUtil.exe again to install the service w/o uninstalling the original version first.
更新代码后,我再次使用 installUtil.exe 来安装服务,而无需先卸载原始版本。
When I now try to uninstall the service, installUtil.exe completes the uninstall successfully, but the service still appears.
当我现在尝试卸载该服务时,installUtil.exe 成功完成了卸载,但该服务仍然出现。
If I try to change its properties, I receive the message 'service is marked for deletion'.
如果我尝试更改其属性,则会收到消息“服务已标记为删除”。
How can I force the deletion (preferrably w/o restarting the server)?
如何强制删除(最好不重新启动服务器)?
回答by the_mandrill
One thing that has caught me out in the past is that if you have the services viewer running then that prevents the services from being fully deleted, so close that beforehand
过去让我感到困扰的一件事是,如果您正在运行服务查看器,则会阻止服务被完全删除,因此请提前关闭
回答by johan
You don't have to restart your machine. Start cmd or PowerShell in elevated mode.
您不必重新启动机器。以提升模式启动 cmd 或 PowerShell。
sc.exe queryex <SERVICE_NAME>
Then you'll get some info. A PID number will show.
然后你会得到一些信息。将显示 PID 编号。
taskkill /pid <SERVICE_PID> /f
Where /f is to force stop.
其中 /f 是强制停止。
Now you can install or launch your service.
现在您可以安装或启动您的服务。
回答by johan
well, you can use SC.EXE to delete any windows Service forcefully if un-install doesnt removes by any chance.
好吧,如果 un-install 万一没有删除,您可以使用 SC.EXE 强行删除任何 Windows 服务。
sc delete <Service_Name>
Read more on "MS Techno Blogging" Deleting Services Forcefully from Services MMC
阅读有关“MS Techno Blogging”从服务 MMC 中强行删除服务的更多信息
回答by Kennifer
I know this isn't going to help, but it might help someone in the future.
我知道这不会有帮助,但它可能会在未来帮助某人。
I've just had the same problem, closing and re-opening the services manager removed both the entry from the registry and completed the uninstall of the service.
我刚刚遇到了同样的问题,关闭并重新打开服务管理器从注册表中删除了两个条目并完成了服务的卸载。
Previous to that, refreshing the services manager hadn't helped.
在此之前,刷新服务管理器并没有帮助。
回答by Aaron Weiker
sc delete sericeName
Just make sure the service is stopped before doing this. I have seen this work most times. There are times where I have seen windows get stuck on something and it insists on a reboot.
在执行此操作之前,请确保服务已停止。我大部分时间都看过这部作品。有时我看到 Windows 卡在某些东西上并且它坚持要重新启动。
回答by incomplete
Close cmd and services window if opened, then start cmd again by right clicking and selecting run as administrator. If sc delete sericeNamedoes not work or anything does not work.
关闭 cmd 和服务窗口(如果打开),然后通过右键单击并选择以管理员身份运行再次启动 cmd。如果sc delete sericeName不起作用或任何东西都不起作用。
回答by seanyboy
Unfortunately, you need to restart the server. That should remove the "deleted" service.
不幸的是,您需要重新启动服务器。那应该删除“已删除”的服务。
回答by Tan
Just in case this answer helps someone: as found here, you might save yourself a lot of trouble running Sysinternals Autorunsas administrator. Just go to the "Services" tab and delete your service.
以防万一这个答案对某人有帮助:如在此处找到的,您可以在以管理员身份运行Sysinternals Autoruns 时省去很多麻烦。只需转到“服务”选项卡并删除您的服务。
It did the trick for me on a machine where I didn't have any permission to edit the registry.
它在我没有任何编辑注册表权限的机器上为我解决了问题。
回答by Fernando Gonzalez Sanchez
You can manually delete the registry key for your service, located at HKLM\SYSTEM\CurrentControlSet\Services, after that you won't see the service in service control manager (need to refresh or reopen to see the change), and you can reinstall the service as usual.
您可以手动删除位于 的服务的注册表项HKLM\SYSTEM\CurrentControlSet\Services,之后您将不会在服务控制管理器中看到该服务(需要刷新或重新打开才能看到更改),您可以照常重新安装该服务。
回答by Dmitry
The following will work without restarting the machine:
以下将在不重新启动机器的情况下工作:
- Search the Registry \ HKEY_LOCAL_MACHINE for < Your Service Name > (both keys and values)
- Set "Legacy" value to 0
- 在注册表 \ HKEY_LOCAL_MACHINE 中搜索 < 您的服务名称 >(键和值)
- 将“传统”值设置为 0

