183

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

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

4

7 回答 7

353

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

sc.exe delete <service name>

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

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

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

于 2008-12-01T13:43:23.510 回答
26

通过注册表删除 Windows 服务

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

  1. 运行RegeditRegedt32

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

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

通过命令行窗口删除 Windows 服务

或者,您也可以使用命令提示符并使用以下命令删除服务:

sc 删除

您还可以使用以下命令创建服务

sc create "MorganTechService" binpath= "C:\Program Files\MorganTechSPace\myservice.exe"

注意:您可能必须重新启动系统才能在服务管理器中更新列表。

于 2013-09-23T16:43:06.837 回答
11

在这里找到

我刚刚在windows XP上试过,它工作

本地计算机: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
于 2008-12-01T13:35:42.513 回答
11

这是删除服务的powershell脚本foo

$foo= Get-WmiObject -Class Win32_Service -Filter "Name='foo'"
$foo.delete()
于 2016-08-04T13:48:40.953 回答
10

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

于 2008-12-01T23:30:39.627 回答
4

我会为此使用 PowerShell

Remove-Service -Name "TestService"

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-service

于 2018-07-11T20:32:29.693 回答
3

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

于 2008-12-01T13:33:45.137 回答