Changing Service State

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

You can use WMI to automatically start and stop services based on certain conditions. This enables you to create scripts that can query the services on multiple computers and then either start or stop specific services based on the criteria specified in the script.

For example, if you have a service with a known memory leak, you might need to periodically stop the service, wait a few minutes, and then restart it. Instead of doing this manually, you can schedule a WMI script to run at a specified interval (for example, every 72 hours) and stop and restart the service.

Alternatively, you can create a script that continuously monitors the memory usage of the process responsible for the service and then automatically stops and restarts the service if memory use exceeds a specified threshold.

The approach you take depends on the nature of the problem. If the service consistently runs for 72 hours without a problem, a scheduled script is the optimal solution: It can stop and restart the service before the memory leak occurs. If the memory leak occurs at more random intervals, continuous monitoring can enable you to identify the problem and fix it immediately, without having to wait until the next time the script is scheduled to run.

In addition to starting and stopping services, WMI can be used to pause services and to resume services that have been paused. The difference between a stopped service and a paused service depends on how the service is created. In general, a stopped service quits functioning and disconnects all users currently using the service. A paused service no longer accepts new connections but continues to support users already connected to the service.

When you control services by using WMI, an error code is returned indicating the success or failure of the operation. These error codes are shown in Table 15.2.

Table 15.2   Service Method Error Codes

ValueDescription
0The request was accepted.
1The request is not supported.
2The user did not have the necessary access.
3The service cannot be stopped because other services that are running are dependent on it.
4The requested control code is not valid, or it is unacceptable to the service.
5The requested control code cannot be sent to the service because the state of the service (Win32_BaseService State property) is equal to 0, 1, or 2.
6The service has not been started.
7The service did not respond to the start request in a timely fashion.
8Unknown failure when starting the service.
9The directory path to the service executable file was not found.
10The service is already running.
11The database to add a new service is locked.
12A dependency this service relies on has been removed from the system.
13The service failed to find the service needed from a dependent service.
14The service has been disabled from the system.
15The service does not have the correct authentication to run on the system.
16This service is being removed from the system.
17The service has no execution thread.
18The service has circular dependencies when it starts.
19A service is running under the same name.
20The service name has invalid characters.
21Invalid parameters have been passed to the service.
22The account under which this service runs is either invalid or lacks the permissions to run the service.
23The service exists in the database of services available from the system.
24The service is currently paused in the system.

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