Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Service dependencies are especially important when you try to stop services. To stop an antecedent service, you must first stop the dependent services. For example, if you attempt to stop the IIS Admin Service without first stopping dependent services such as FTP, SMTP, and World Wide Web Publishing Service, you receive an error message, and all the services continue to run.
Dependencies also affect the order in which services start. To start a dependent service, the antecedent service must start first. If you are starting a dependent service such as FTP, the antecedent service (IIS Admin) automatically starts first. Only after IIS Admin starts does the FTP service start.
However, starting the antecedent service first does not cause a dependent service to start. If you start the IIS Admin Service, that service itself starts, but its dependent services (such as FTP) do not automatically start at the same time.
In other words, stopping and restarting an antecedent service sometimes involves stopping and restarting a number of dependent services. You could do this manually coding all the dependencies within your script. The difficulty with this approach is twofold. First, you must determine all the dependencies and manually add them to the script. Second, if those dependencies ever change (because of a service or operating system upgrade), your script must be modified to reflect these changes.
Alternatively, you can use WMI to enumerate the dependencies, and then stop and restart the appropriate services in the appropriate order. By using WMI, you avoid the problems of hard-coding service dependencies: you do not have to determine these dependencies beforehand, and you do not have to be concerned that changes to the operating system affect these dependencies. Instead, WMI determines the appropriate dependencies each time the script runs.
The scripts for stopping and starting dependent services perform similar steps but in the opposite order.
Listing 15.16 contains a script that stops the IIS Admin Service and all its dependents. To carry out this task, the script must perform the following steps:
This query must use an Associators of query and specify the following information:
The query returns a collection consisting of all the services dependent on the IIS Admin Service.
Listing 15.16 Stopping a Service and Its Dependents
|
|
To start a service and all its dependents, simply reverse the process for stopping a service and its dependents: start the antecedent service, obtain a list of dependent services, and start each one. Listing 15.17 contains a script that starts the IIS Admin Service and all its dependents.
Listing 15.17 Starting Dependent Services
|
|
Send us your feedback | « Previous | Next » |