O'Reilly logo

Active Directory, Second Edition by Alistair G. Lowe-Norris, Robbie Allen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Manipulating Services

Querying services is simple to do with WMI. The Win32_Service class is the WMI representation of a service. The Win32_Service class contains a lot of property methods that provide information about the service; the most useful ones have been listed in Table 26-2.

Table 26-2. Useful Win32_Service properties

Property

Description

AcceptPause

Returns a Boolean indicating whether the service can be paused.

AcceptStop

Returns a Boolean indicating whether the service can be stopped.

Description

Description of the service.

DisplayName

Display name of the service.

Name

Unique string identifier for the service.

PathName

Fully qualified path to the service executable.

Started

Boolean indicating whether the service has been started.

StartMode

String specifying the start mode of the service. Will be one of Automatic, Manual, or Disabled.

StartName

Account under which the service runs.

State

Current state of the service. Will be one of Stopped, Start Pending, Stop Pending, Running, Continue Pending, Pause Pending, Paused, or Unknown.

The following script retrieves all the running services on a machine. All we need to do is use a WQL query that finds all Win32_Service objects that have a state of “Running”:

strComputer = "." Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set objServices = objWMI.ExecQuery _ ("SELECT * FROM Win32_Service WHERE State = 'Running'") For Each objService in objServices Wscript.Echo objService.DisplayName ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required