当系统上没有可执行文件时,如何卸载 Windows 服务?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/330836/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:48:13  来源:igfitidea点击:

How to uninstall a Windows Service when there is no executable for it left on the system?

windowswindows-servicesuninstall

提问by Magnus Lindhe

How do I uninstall a Windows Service when there is no executable for it left on the system? I can not run installutil -usince there is not executable left on the system. I can still see an entry for the service in the Services console.

当系统上没有可执行文件时,如何卸载 Windows 服务?我无法运行,installutil -u因为系统上没有可执行文件。我仍然可以在服务控制台中看到该服务的条目。

The reason for this state is probably because of a problem in the msi package that does not remove the service correctly, but how do I fix it once the service is in this state?

出现这种状态的原因可能是msi包有问题,没有正确删除服务,但是一旦服务处于这种状态如何修复呢?

回答by Treb

You should be able to uninstall it using sc.exe (I think it is included in the Windows Resource Kit) by running the following in an "administrator" command prompt:

通过在“管理员”命令提示符中运行以下命令,您应该能够使用 sc.exe(我认为它包含在 Windows 资源工具包中)卸载它:

sc.exe delete <service name>

where <service name>is the name of the service itself as you see it in the service management console, not of the exe.

<service name>您在服务管理控制台中看到的服务本身的名称在哪里,而不是 exe 的名称。

You can find sc.exe in the System folder and it needs Administrative privileges to run. More information in this Microsoft KB article.

您可以在 System 文件夹中找到 sc.exe,它需要管理权限才能运行。此 Microsoft KB 文章中的更多信息

Alternatively, you can directly call the DeleteService()api. That way is a little more complex, since you need to get a handle to the service control manager via OpenSCManager()and so on, but on the other hand it gives you more control over what is happening.

或者,您可以直接调用DeleteService()api。这种方式有点复杂,因为您需要通过OpenSCManager()等获得服务控制管理器的句柄,但另一方面,它可以让您更好地控制正在发生的事情。

回答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:

如果您知道正确的路径,从注册表中删除服务非常容易。这是我如何做到的:

  1. Run Regeditor Regedt32

  2. Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"

  3. 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).

  1. 运行RegeditRegedt32

  2. 转到注册表项“HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services”

  3. 查找要删除的服务并将其删除。您可以查看密钥以了解服务正在使用哪些文件并删除它们(如有必要)。

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 Fredou

found here

在这里找到

I just tried on windows XP, it worked

我刚刚在 Windows XP 上试过,它有效

local computer: sc \\. delete [service-name]

本地计算机:sc \\. 删除 [服务名称]

  Deleting services in Windows Server 2003

  We can use sc.exe in the Windows Server 2003 to control services, create services and delete services. Since some people thought they must directly modify the registry to delete a service, I would like to share how to use sc.exe to delete a service without directly modifying the registry so that decreased the possibility for system failures.

  To delete a service: 

  Click “start“ - “run“, and then enter “cmd“ to open Microsoft Command Console.

  Enter command:

  sc servername delete servicename

  For instance, sc \dc delete myservice

  (Note: In this example, dc is my Domain Controller Server name, which is not the local machine, myservice is the name of the service I want to delete on the DC server.)

  Below is the official help of all sc functions:

  DESCRIPTION:
    SC is a command line program used for communicating with the
    NT Service Controller and services. 
  USAGE:
          sc

回答by Nima Soroush

Here is the powershell script to delete a service foo

这是删除服务的powershell脚本 foo

$foo= Get-WmiObject -Class Win32_Service -Filter "Name='foo'"
$foo.delete()

回答by Thomas Bratt

My favourite way of doing this is to use Sysinternals Autorunsapplication. Just select the service and press delete.

我最喜欢的方法是使用Sysinternals Autoruns应用程序。只需选择服务,然后按删除。

回答by Samiksha

Create a copy of executables of same service and paste it on the same path of the existing service and then uninstall.

创建相同服务的可执行文件的副本并将其粘贴到现有服务的相同路径上,然后卸载。