Determining Which Services Can Be Stopped or Paused

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Not all services can be stopped, and even fewer services can be paused. The capability of being stopped or paused must be coded into the service itself; without this code, the service does not respond to stop or pause requests. In particular, services that run as part of Services.exe (the process that is also responsible for running the SCM) can be neither stopped nor paused. If Services.exe could be stopped, that would stop the SCM. Without the SCM, all other services on the computer would be unable to function.

You can query the WMI AcceptStop and the AcceptPause properties to determine which services can be paused and which services can be stopped. For example, of the 88 services installed on a particular Windows 2000 domain controller, 54 were capable of being stopped, but only 17 were capable of being paused.

Scripting Steps

The scripts for determining which services can be stopped or which services can be paused are similar.

Determining which services can be stopped

Listing 15.7 contains a script that displays a list of services that can be stopped. To carry out this task, the script must perform the following steps.

  1. Create a variable to specify the computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  3. Use the ExecQuery method to query the Win32_Service class. To restrict data retrieval to those services that can be stopped, a Where clause is included that returns only services for which the AcceptStop property is True.
  4. For each service in the collection, echo the service display name.

Listing 15.7   Determining Which Services Can Be Stopped

1 2 3 4 5 6 7 8 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServices = objWMIService.ExecQuery _     ("SELECT * FROM Win32_Service WHERE AcceptStop = True") For Each objService in colServices     Wscript.Echo objService.DisplayName Next

Determining which services can be paused

To determine which services can be paused, you can use a script similar to Listing 15.7 but substitute the AcceptPause property for the AcceptStop property in the Where clause, as shown in Listing 15.8. The output displayed in the command window lists the services that can be paused instead of those that can be stopped.

Listing 15.8   Determining Which Services Can Be Paused

1 2 3 4 5 6 7 8 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServices = objWMIService.ExecQuery _     ("SELECT * FROM Win32_Service WHERE AcceptPause = True") For Each objService in colServices     Wscript.Echo objService.DisplayName Next

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net