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

时间:2008-12-01 13:31:16

标签: windows windows-services uninstall

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

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

7 个答案:

答案 0 :(得分:309)

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

sc.exe delete <service name>

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

您可以在System文件夹中找到sc.exe,它需要管理权限才能运行。 More information in this Microsoft KB article

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

答案 1 :(得分:24)

通过注册表删除Windows服务

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

  1. 运行 Regedit Regedt32

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

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

  4. 通过命令窗口删除Windows服务

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

    sc删除

    您还可以使用以下命令

    创建服务

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

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

答案 2 :(得分:11)

found here

我刚刚在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

答案 3 :(得分:9)

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

答案 4 :(得分:9)

以下是删除服务foo

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

答案 5 :(得分:3)

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

答案 6 :(得分:1)

我将为此使用PowerShell

Remove-Service -Name "TestService"

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