Friday, August 15, 2008

How do you remove a windows service?

manually remove windows service registry sc

OK, I've uninstalled some software but it's left a service definition. It can't do much harm as most (but not all) of the resources it needs have been removed ... but I can't ignore it - how do you get rid of it?

Note to self: before uninstalling software with services it may help to stop them all and possibly disable them all too? I think this is why this particular thing could not be removed.

Note to developers: stop and remove services as part of uninstall programs.

Some solutions talk about using regedit and modifying:

A better approach is to use sc ".. a command line program used for communicating with the Service Control Manager and services".

It should be as simple as:
sc delete [service name]

But the tricky thing is getting the name of the service right. What you see in the Service window is the display name not the service name. Use:
sc query state= all

To get a listing like
SERVICE_NAME: ExampleService
DISPLAY_NAME: Example Service That I Want To Delete
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 1  STOPPED
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN))
        WIN32_EXIT_CODE    : 1077  (0x435)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0


DISPLAY_NAME: Help and Support
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN))
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0


So the above example listing:
sc delete ExampleService

Just type sc at the command prompt for usage and more example commands (hit y to get help for the sc query commands).