ChatGPT解决这个技术问题 Extra ChatGPT

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

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

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?


C
CodeNaked

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

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

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.


It did exactly what I wanted and removed the service from the registry. It doesn't show up in the Services console any more. Thanks!
I get "Access is denied." What to do next?
Just a note for whoever trying to execute command in Method 1 in PowerShell: sc is not for communicating with service control manager. It is Set-Content command. Use sc.exe instead.
If you get error 1072, make sure you don't have the services control panel open (see this other question)
I was getting the below error. [SC] OpenService FAILED 1060: The specified service does not exist as an installed service. Later tried the same with power shell and it works !
C
Community

Remove Windows Service via Registry

Its very easy to remove a service from registry if you know the right path. Here is how I did that:

Run Regedit or Regedt32 Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services" 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).

Delete Windows Service via Command Window

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"

Note: You may have to reboot the system to get the list updated in service manager.


Is doing it the registry way safe? Is the "final result" of the registry way the same as the "final result" of sc delete?
No, I just tried deleting a service from regedit directly. As as result, now the the entry of the service I wanted deleted remains in Service, while the Description of it shows: ""
N
Nima Soroush

Here is the powershell script to delete a service foo

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

nice script, thanks for sharing Nima!
Works perfectly for removing a service located only on the services tab within Task Manager, but not located in Services.msc. Not sure what it would do if the service existed in both locations.
F
Fredou

found here

I just tried on windows XP, it worked

local computer: sc \\. delete [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

T
Thomas Bratt

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


Why not simply use sc delete?
J
JoeRod

I'd use PowerShell for this

Remove-Service -Name "TestService"

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


only available in PS6
I was getting the below error. [SC] OpenService FAILED 1060: The specified service does not exist as an installed service. Later tried sc delete with power shell and it works ! Thanks to the idea of power shell.
S
Samiksha

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


That's a good suggestion. If that doesn't work he may need to reinstall, run installutil -u, and then uninstall
do we have to create the copy of same exe or renaming any other file would work fine?
@Samiksha, I thought he said he didn't have "a copy of executables"?