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

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

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

322965 次浏览

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

在这里发现的

我刚试了 Windows XP,成功了

本地电脑: 删除[ service-name ]

  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

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

sc.exe delete <service name>

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

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

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

我最喜欢的方法是使用 系统内部自动运行应用程序。只要选择服务,按删除。

通过注册表删除 Windows 服务

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

  1. 运行 注册或 < strong > Regedt32

  2. 转到注册表项“ HKEY _ LOCAL _ MACHINE/SYSTEM/CurrentControlSet/Services”

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

通过命令窗口删除 Windows 服务

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

Sc 删除

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

Sc create“ MorganTechService”binpath = “ C: Program Files MorganTechSPace myservice.exe”

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

下面是用于删除服务 foo的 powershell 脚本

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