Configuring Error Control Codes for Autostart Services

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

When a computer starts, all the autostart services also start. On occasion, one of these services might fail to start along with the computer. When a service fails during system startup, the computer takes action based on the value of the service error control code. These codes and the corresponding actions are listed in Table 15.5.

Also listed in the table are the values that must be used to configure the error control code. Admittedly, this can be a bit confusing. Although error control codes are reported as strings (such as Ignore), you must configure these codes using integers. For example, this line of code sets an error control code to Critical:

errReturn = objService.Change( , , , 3) 

Regardless of the error control code, all startup failures are recorded in the System Event Log.

Table 15.5   Service Error Control Codes

Error codeValueDescription
Ignore0Startup continues. No notification is given to the user that the service failed.
Normal1Startup continues. Before the user logs on, the user receives the notification, "At least one service or device failed during startup."
Severe2Computer attempts to restart with last-known good configuration. If the service fails again, startup continues and notification is given to the user.
Critical3Computer attempts to restart with last-known good configuration. If the service fails again, startup stops.

Most Windows 2000 services are installed using the Normal error control code. A few of the exceptions, which are installed using the Ignore error code, include:

  • File Replication Service
  • Smart Card
  • Secondary Logon
  • WMI

For the services installed using the Ignore error code, no notification is given to the user that the service has failed. If you prefer on-screen notification that a service could not start, you can use WMI to change the error control code.

Error control codes apply only to computer startup; error control codes are not used if you stop and then attempt to restart a service after the computer is running.

Scripting Steps

Listing 15.19 contains a script that changes the error control code to Normal for all services that currently have the error control code Ignore. 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 a subset of services, a Where clause is used to limit data retrieval only to those services for which the ErrorControl property is equal to Manual.
  4. For each service in the collection, use the Change method set ErrorControl to Normal.

    With the Change method, the ErrorControl property must be the fourth parameter in the list of arguments supplied. Because of this, three empty arguments (represented by the three commas) must precede the new value for ErrorControl.

Listing 15.19   Configuring Service Error Control Codes

1 2 3 4 5 6 7 8 9 
Const NORMAL = 1 strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery _     ("SELECT * FROM Win32_Service WHERE ErrorControl = 'Ignore'") For Each objService in colServiceList     errReturn = objService.Change( , , , NORMAL) 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