本文翻译自:How to solve “The specified service has been marked for deletion” error
I try to remove a Windows Service with sc delete <service name>
, and encounter the following error: 我尝试使用sc delete <service name>
Windows服务,并遇到以下错误:
[SC] DeleteService FAILED 1072: [SC] DeleteService失败1072:
The specified service has been marked for deletion. 指定的服务已标记为删除。
What I've already done: 我已经完成的工作:
Stopped the service, obviously. 显然,已停止服务。 The
sc queryex "<service name>"
gives the following result:sc queryex "<service name>"
给出以下结果:SERVICE_NAME: Stub service TYPE : 10 WIN32_OWN_PROCESS STATE : 1 STOPPED WIN32_EXIT_CODE : 1067 (0x42b) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 PID : 0 FLAGS :
Ensured that Microsoft Management Console is closed (
taskkill /F /IM mmc.exe
), 确保关闭了Microsoft管理控制台 (taskkill /F /IM mmc.exe
),Removed the key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\<service name> from the registry . 从注册表中删除了键HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services \\ <服务名称> 。
Due to this removal,
services.msc
still shows the service (with a name, but no status or startup type), but the description is “<Failed to Read Description. 由于此删除,services.msc
仍显示该服务(带有名称,但没有状态或启动类型),但是描述为“ <无法读取描述。 Error Code: 2 >”. 错误代码:2>”。 When attempting to view the properties, “The system cannot find the file specified.” is shown five times. 尝试查看属性时,显示五次“系统找不到指定的文件。”。
The problem persists. 问题仍然存在。
What is the next step? 你下一步怎么做?
#1楼
参考:https://stackoom.com/question/1OH70/如何解决-指定的服务已被标记为删除-错误
#2楼
There may be several causes which lead to the service being stuck in “marked for deletion”. 可能有多种原因导致服务卡在“标记为删除”中。
SysInternals' Process Explorer is opened . SysInternals的Process Explorer打开 。 Closing it should lead to automatic removal of the service. 关闭它会导致服务自动删除。
Microsoft Management Console (MMC) is opened . Microsoft管理控制台(MMC)已打开 。 To ensure all instances are closed, run
taskkill /F /IM mmc.exe
. 要确保关闭所有实例,请运行taskkill /F /IM mmc.exe
。Services console is opened . 服务控制台已打开 。 This is the same as the previous point, since Services console is hosted by MMC. 这与上一点相同,因为Services控制台由MMC托管。
Event Viewer is opened . 事件查看器已打开 。 Again, this is the same as the third point. 同样,这与第三点相同。
The key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\{service name} exists . 密钥HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services \\ {服务名称}存在 。
Someone else is logged into the server and has one of the previously mentioned applications opened. 其他人登录到服务器 ,并打开了前面提到的应用程序之一。
An instance of Visual Studio used to debug the service is open. 用于调试服务的Visual Studio实例已打开。
#3楼
This can also be caused by leaving the Services console open. 这也可能是由于打开服务控制台导致的。 Windows won't actually delete the service until it is closed. 在关闭服务之前,Windows实际上不会删除该服务。
#4楼
In my case, it was caused by unhandled exception while creating eventLog source. 就我而言,这是由创建eventLog源时未处理的异常引起的。 Use try catch to pin point the cause. 使用try catch查明原因。
#5楼
发现了另一项要检查的内容-在任务管理器中查找-如果其他用户已连接到此框,即使他们已“断开连接”,您也必须实际注销他们才能最终删除该服务。
#6楼
Deleting registry keys as suggested above got my service stuck in the stopping state. 如上所述删除注册表项会使我的服务陷入停止状态。 The following procedure worked for me: 以下过程对我有用:
open task manager > select services tab > select the service > right click and select "go to process" > right click on the process and select End process 打开任务管理器>选择服务选项卡>选择服务>右键单击并选择“转到流程”>右键单击该流程,然后选择“结束流程”
Service should be gone after that 在那之后服务应该消失了