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
Open the Service Creation Wizard (srvinstw.exe).
Select Remove a service and click Next.
Select the target machine from which to remove the service and click Next.
Select the service you want to remove and click Next.
Click OK to confirm removal of the service.
Using a command-line interface:
The following commands stop a service and remove it:
<ServiceName>stop > instsrv
' This code removes a service. ' ------ SCRIPT CONFIGURATION ------ 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 ...