Enumerating Antecedent Services

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Antecedent services are services that must be running before dependent services can start. This information is extremely valuable for anyone writing scripts that automatically start services. By enumerating the antecedent services, you can ensure that all required services are already running before you attempt to start a dependent service. Alternatively, by enumerating antecedent services, you can also determine which dependent services you might not want to start. When you start a dependent service, its antecedent services automatically start; in some cases, you might prefer to leave those services inactive.

Antecedent services can be enumerated by using a script similar to the one used to enumerate dependent services. If you set the service role to Dependent in your WMI script, it lists the antecedents for a particular service.

Scripting Steps

Listing 15.15 contains a script that enumerates the antecedents of the Fax service. 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.

    This query must use an Associators of query and specify the following information:

    • The instance of the service on which the query is performed (Win32_Service.Name = Fax ).
    • The name of the Association class (AssocClass = Win32_DependentService). If the class name were not specified, the query would return all associated classes and their instances.
    • The role played by the Fax service. In this case, Fax is dependent on the services the query returns.

    This returns a collection consisting of all the services for which the Fax service is a dependent.

  4. For each service in the collection, echo the service display name.

Listing 15.15   Enumerating Antecedent Services

1 2 3 4 5 6 7 8 9 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery _     ("ASSOCIATORS OF {Win32_Service.Name='fax'} WHERE " _         & "AssocClass=Win32_DependentService Role=Dependent" ) For Each objService in colServiceList     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