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

Mag*_*dhe 163 windows windows-services uninstall

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

这种状态的原因可能是因为msi包中的问题没有正确删除服务,但是一旦服务处于这种状态,我该如何解决?

Tre*_*reb 319

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

sc.exe delete <service name>
Run Code Online (Sandbox Code Playgroud)

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

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

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

  • 对于尝试在PowerShell中的方法1中执行命令的人,只需注意:sc不用于与服务控制管理器通信.它是Set-Content命令.请改用sc.exe. (4认同)
  • @Nick使用管理员命令提示符 (4认同)

kom*_*bsh 24

通过注册表删除Windows服务

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

  1. 运行Regedit或Regedt32

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

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

通过命令窗口删除Windows服务

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

sc删除

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

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

注意:您可能必须重新引导系统才能在服务管理器中更新列表.

  • 不,我只是尝试直接从regedit删除服务.结果,现在我想要删除的服务的条目仍在服务中,而它的描述显示:"<无法读取描述.错误代码:2>" (5认同)
  • 这有效,但请确保重启! (5认同)
  • 这样做是注册表安全吗?注册表方式的"最终结果"是否与"sc delete"的"最终结果"相同? (3认同)

Fre*_*dou 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
Run Code Online (Sandbox Code Playgroud)


Nim*_*ush 10

这是删除服务的powershell脚本 foo

$foo= Get-WmiObject -Class Win32_Service -Filter "Name='foo'"
$foo.delete()
Run Code Online (Sandbox Code Playgroud)


Tho*_*att 9

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