如果文件不再存在,如何卸载 Windows 服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/197876/
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 do I uninstall a Windows service if the files do not exist anymore?
提问by Thomas Jespersen
How do I uninstall a .NET Windows Service, if the service files does not exists anymore?
如果服务文件不再存在,如何卸载 .NET Windows 服务?
I installed a .NET Windows Service using InstallUtil. I have since deleted the files but forgot to run
我使用 InstallUtil 安装了 .NET Windows 服务。我已经删除了文件但忘了运行
InstallUtil /u
first. So the service is still listed in the Services MMC.
第一的。因此该服务仍列在服务 MMC 中。
Do I have to go into the registry? Or is there a better way?
我必须进入注册表吗?或者,还有更好的方法?
回答by Jorge Ferreira
You have at least three options. I have presented them in order of usage preference.
你至少有三个选择。我已经按照使用偏好的顺序介绍了它们。
Method 1- You can use the SC tool(Sc.exe) included in the Resource Kit. (included with Windows 7/8)
方法 1- 您可以使用资源工具包中包含的SC 工具(Sc.exe)。(包含在 Windows 7/8 中)
Open a Command Prompt and enter
打开命令提示符并输入
sc delete <service-name>
Tool help snippet follows:
工具帮助片段如下:
DESCRIPTION:
SC is a command line program used for communicating with the
NT Service Controller and services.
delete----------Deletes a service (from the registry).
Method 2- use delserv
方法 2- 使用 delserv
Downloadand use delserv command line utility. This is a legacy tool developed for Windows 2000. In current Window XP boxes this was superseded by sc described in method 1.
下载并使用 delserv 命令行实用程序。这是为 Windows 2000 开发的遗留工具。在当前的 Window XP 机器中,它被方法 1 中描述的 sc 取代。
Method 3- manually delete registry entries (Note that this backfires in Windows 7/8)
方法 3- 手动删除注册表项(请注意,这在 Windows 7/8 中适得其反)
Windows services are registered under the following registry key.
Windows 服务在以下注册表项下注册。
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
Search for the sub-key with the service name under referred key and delete it. (and you might need to restart to remove completely the service from the Services list)
在被引用的键下搜索具有服务名称的子键并删除它。(您可能需要重新启动才能从“服务”列表中完全删除该服务)
回答by Dean Hill
From the command prompt, use the Windows "sc.exe" utility. You will run something like this:
在命令提示符下,使用 Windows“sc.exe”实用程序。你会运行这样的:
sc delete <service-name>
回答by Michael
Notes on using "sc delete" in Windows 8:
在 Windows 8 中使用“sc delete”的注意事项:
1) Open a CMD window with elevated privileges. [Windows Key-X to bring up a menu with the option; select "Command Prompt (Admin)".]
2) Use the parenthetical name from the list in Services [for example, I used "sc delete gupdate" when, in Services, it read "Google Update (gupdate)"]
1) 打开具有提升权限的 CMD 窗口。[Windows Key-X 调出带有选项的菜单;选择“命令提示符(管理员)”。]
2)使用服务中列表中的括号名称[例如,我使用了“sc delete gupdate”,而在服务中,它显示为“Google Update (gupdate)”]
回答by Robin French
Some people mentioning sc delete
as an answer. This is how I did it, but it took me a while to find the <service-name>
parameter.
有些人提到sc delete
作为答案。我就是这样做的,但是我花了一段时间才找到<service-name>
参数。
The command sc query type= service
(note, it's very particular with formatting, the space before "service" is necessary) will output a list of Windows services installed, complete with their qualified name to be used with sc delete <service-name>
command.
该命令sc query type= service
(注意,它的格式非常特殊,“服务”之前的空格是必需的)将输出已安装的 Windows 服务列表,以及它们与sc delete <service-name>
命令一起使用的限定名称。
The list is quite long so you may consider piping the output to a text file (i.e. >> C:\test.txt
) and then searching through that.
该列表很长,因此您可以考虑将输出传送到文本文件(即>> C:\test.txt
),然后搜索该文件。
The SERVICE_NAME
is the one to use with sc delete <service-name>
command.
的SERVICE_NAME
是使用一个sc delete <service-name>
命令。
回答by kombsh
Remove Windows Service via Registry
通过注册表删除 Windows 服务
Its very easy to remove a service from registry if you know the right path. Here is how I did that:
如果您知道正确的路径,从注册表中删除服务非常容易。这是我如何做到的:
Run Regeditor Regedt32
Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"
Look for the service that you want delete and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).
运行Regedit或Regedt32
转到注册表项“HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services”
查找要删除的服务并将其删除。您可以查看密钥以了解服务正在使用哪些文件并删除它们(如有必要)。
Delete Windows Service via Command Window
通过命令窗口删除 Windows 服务
Alternatively, you can also use command prompt and delete a service using following command:
或者,您也可以使用命令提示符并使用以下命令删除服务:
sc delete
删除
You can also create service by using following command
您还可以使用以下命令创建服务
sc create "MorganTechService" binpath= "C:\Program Files\MorganTechSPace\myservice.exe"
sc create "MorganTechService" binpath="C:\Program Files\MorganTechSPace\myservice.exe"
Note: You may have to reboot the system to get the list updated in service manager.
注意:您可能必须重新启动系统才能在服务管理器中更新列表。
回答by Mike de Klerk
If you wish to use a tool for it you could use Process Hacker
如果你想使用一个工具,你可以使用Process Hacker
Form to create the service:
创建服务的表单:
Context menu on a service to delete it:
用于删除服务的上下文菜单:
I find Process Hacker a more convient tool to manage Windows processes and services than Windows's own Taskmgr.exe. Especially on Windows XP, where you can't access services at all from task manager.
我发现 Process Hacker 是一种比 Windows 自己的 Taskmgr.exe 更方便的管理 Windows 进程和服务的工具。尤其是在 Windows XP 上,您根本无法从任务管理器访问服务。
回答by user1208639
I needed to reinstall my tomcat service, which meant first removing it. This worked for me:
我需要重新安装我的 tomcat 服务,这意味着首先将其删除。这对我有用:
Start a command prompt window using run as administrator
sc query type= service >t.txt
(edit the file t.txt, search through the list and find the tomcat service. It's called Tomcat7)
(编辑t.txt文件,在列表中搜索,找到tomcat服务,名为Tomcat7)
sc delete Tomcat7
HOWEVER, the query command did not work the first time, because the tomcat service was not running. It seems to only list services that are running. I had to start the service and run the query command again.
但是,第一次查询命令不起作用,因为tomcat服务没有运行。它似乎只列出正在运行的服务。我不得不启动服务并再次运行查询命令。
回答by ja928
If the original Service .InstallLog and .InstallState files are still in the folder, you can try reinstalling the executable to replace the files, then use InstallUtil /u, then uninstall the program. It's a bit convoluted, but worked in a particular instance for me.
如果原来的Service .InstallLog 和.InstallState 文件还在文件夹中,您可以尝试重新安装可执行文件来替换文件,然后使用InstallUtil /u,然后卸载程序。这有点令人费解,但在特定情况下对我有用。
回答by Tan
回答by Sree
1st Step : Move to the Directory where your service is present
第一步:移动到您的服务所在的目录
Command : cd c:\xxx\yyy\service
命令:cd c:\xxx\yyy\service
2nd Step : Enter the below command
第二步:输入以下命令
Command : C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe service.exe \u
命令:C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe service.exe \u
Here service.exe is your service exe and \u will uninstall the service. you'll see "The uninstall has completed" message.
这里 service.exe 是您的服务 exe,\u 将卸载该服务。您将看到“卸载已完成”消息。
If you wanna install a service, Remove \u in the above command which will install your service
如果你想安装一个服务,在上面的命令中删除 \u 这将安装你的服务