7.3. Removing a Service


You want to remove a service. When you uninstall an application that previously installed a service, the service will automatically be removed. However, if you manually installed the service as described in Recipe 7.2, you'll need to manually remove it to uninstall it.


Before you can remove a service, you need to make sure the service is not running. See Recipe 7.1 for more on stopping a service.

Using a graphical user interface

  1. Open the Service Creation Wizard (srvinstw.exe).

  2. Select Remove a service and click Next.

  3. Select the target machine from which to remove the service and click Next.

  4. Select the service you want to remove and click Next.

  5. Click Finish.

  6. Click OK to confirm removal of the service.

Using a command-line interface:

The following commands stop a service and remove it:

> sc <ServiceName> stop
> instsrv <ServiceName> remove

Using VBScript

' This code removes a service.
strComputer     = "<ServerName>"  ' e.g., fs-rtp01 (use . for local server)
strSvcName      = "<ServiceName>" ' e.g., MyMonitor boolStopService = TRUE ' e.g., TRUE to attempt to stop the service ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objService = objWMI.Get("Win32_Service.Name='" & strSvcName & "'") if boolStopService = TRUE then intRC = objService.StopService WScript.Sleep 5000 ' Give the service 5 seconds to stop if intRC > 0 then WScript.Echo "Error stopping service: " & intRC ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.