Installing Services

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Services are generally installed in one of two ways: either as a part of the operating system installation or by using an installation program provided by the service developer. However, some services, particularly those created in-house, might not have an installation program. In those instances, you can use the Win32_Service Create method to programmatically install services.

Despite the name, the Create method does not actually create a service; it merely installs an existing service. To use this command, you need to copy the service executable file to a computer and then use Win32_Service Create to install the service.

The Create method is similar to the Change method. In both cases, the properties of the service are passed as parameters to the method. As with the parameters used with the Change method, the order in which these parameters are passed is very important. You must pass the parameters in the order shown in Table 15.6.

A complete list of the service properties exposed to the Win32_Service Create method are shown in Table 15.6. For more information about each property, see "Retrieving Service Properties" earlier in this chapter.

Note

  • The ordinal positions of the service properties exposed to the Create method differ slightly from those exposed to the Change method. Make sure you use the values shown in Table 15.6 when installing a service.

Table 15.6   Service Properties Exposed to the WMI Create Method

PositionProperty
1Name Name of the service as stored in the registry.
2DisplayName Name of the service as displayed in the Services snap-in.
3PathName Full path to the service s executable file.
4ServiceType Type of service.
5ErrorControl Action to be taken should a service fail during startup.
6StartMode Method used to start the service.
7DesktopInteract Indicates whether the service can create or communicate with windows on the desktop.
8StartName Account name under which the service runs.
9StartPassword Password for the account name specified by StartName.
10LoadOrderGroup Load-ordered group to which the service belongs.
11LoadOrderGroupDependencies Set of load-ordered groups that must be running before this service can start.
12ServiceDependencies Services that must be running before this service can start.

Scripting Steps

Listing 15.22 contains a script that installs a service named DbService. To carry out this task, the script must perform the following steps:

  1. Create a constant named OWN_PROCESS, and set the value to 16.

    This constant is used to specify that the service must run in its own process.

  2. Create a constant named NOT_INTERACTIVE, and set the value to True.

    This constant indicates that the service does not interact with the desktop.

  3. Create a variable to specify the computer name.
  4. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  5. Get an instance of the Win32_BaseService class, the parent class for Windows services.
  6. Use the Create method to create (install) a new service.

    To create the service, include the following parameters:

    • DbService. Name of the service as it is stored in the registry.
    • Personnel Database Service. "Friendly" name of the service, as viewed in the Services snap-in.
    • C:\Windows\System32\Db.exe. Local path to the executable file for the service.
    • OWN_PROCESS. Service runs in its own process.
    • Normal. Error control code for the service.
    • Auto. Service startup type.
    • NOT_INTERACTIVE. Service does not interact with the desktop.
    • .\LocalService. Account name under which the service runs. (Two backslashes are not required in the name, because the name, and its single backslash, is not being used in a query.)

      You must specify a valid account name when installing a service. If the SCM cannot locate the specified account, installation fails.

    • . Empty string indicating that the LocalService account does not use a password.

      If you specify an incorrect password, installation continues because the SCM does not verify passwords when installing a service. However, if the password is incorrect, the service fails when you try to start it.

Listing 15.22   Installing a Service

1 2 3 4 5 6 7 8 9 
Const OWN_PROCESS = 16 Const NOT_INTERACTIVE = True strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objService = objWMIService.Get("Win32_BaseService") errReturn = objService.Create ("DbService", "Personnel Database", _  "c:\windows\system32\db.exe", OWN_PROCESS ,2 ,"Automatic" , _       NOT_INTERACTIVE ,".\LocalSystem" ,"")

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