Configuring Services

Microsoft® Windows® 2000 Scripting Guide

Although services generally require little hands-on administration, there will be times when you need to reconfigure a service. For example, you might want to configure a service so that it starts automatically each time the computer starts. Alternatively, you might want to change the display name of a service, making the service and its function more obvious to administrators working in the Services snap-in. Management tasks such as these can be carried out using WMI.

The WMI Win32_Service Change method is especially useful for changing selected service properties on multiple computers throughout the enterprise. The Change method accepts 11 parameters, each representing a service property that can be modified. When passing these parameters, it is important to maintain the correct order. For example, PathName is the second parameter in the set of 11 parameters. To change this property, the new value for PathName must be the second item in the parameters passed to the Change method.

This means you must pass a value of some kind for DisplayName, the first item in the parameter list. If you do not want to change the current value of DisplayName, you can insert a comma for that value. For example, the following code changes just the PathName:

errReturn = strService.Change( , "c:\windows\services\new_name.exe")

Because these single commas might be confusing to someone editing your script, you can instead insert the keyword Null or use a constant with the value Null. For example, you might create a constant named SAME_DISPLAYNAME, set it to Null, and then insert the constant into the parameter string as follows:

Const SAME_DISPLAYNAME  = Null
errReturn = strService.Change _
    (SAME_DISPLAYNAME , "c:\windows\services\new_name.exe")

This makes it clearer that you are keeping the same display name and changing only the service path.

Table 15.3 provides a complete list of the service properties exposed to the Change method, as well as their ordinal position. The items that can be changed by using WMI represent only a subset of a service's full property set and do not include some properties, such as service description.

Table 15.3 Service Properties Exposed to the WMI Change Method

Position

Property

1

DisplayName - Name of the service as displayed in the Services snap-in.

2

PathName - Full path to the service's executable file.

3

ServiceType - Type of service. Most services are type 4: services that run in their own process.

Valid services types include the following:

1 - Kernel driver

2 - File system driver

3 - Adapter

4 - Own process

5 - Win32 shared process

4

ErrorControl - Action to be taken if a service fails during startup.

Valid error controls include the following:

0 - Ignore

1 - Normal

2 - Severe

3 - Critical

5

StartMode Method used to start the service. Most service start modes are either Auto or Manual.

Valid start modes include the following:

6

DesktopInteract Indicates whether the service can create or communicate with windows on the desktop. DesktopInteract can be set to either TRUE or FALSE. Interactive services must run under the LocalSystem account.

7

StartName - Account name under which the service runs. If not specified, the service runs under the LocalSystem account.

8

StartPassword - Password for the account name specified by StartName. Use an empty string ("") to specify no password and NULL to indicate that you are not changing the current password.

9

LoadOrderGroup - Load-ordered group to which the service belongs. When you start services as part of the computer start process, those that belong to load-ordered groups start first, services that belong to groups (but not load-ordered groups) start next, and services that do not belong to groups of any kind start last.

10

LoadOrderGroupDependencies - Set of load-ordered groups that must be running before this service can start.

11

ServiceDependencies - Services that must be running before this service can start.