wntSvcCreate

Adds a service to the service control manager database.

Syntax:

wntSvcCreate(server-name, string-values, numeric-values, dependencies, reserved)

Parameters:

(s) server-name: the UNC name of the server on which the function will execute (e.g., "\\MYSERVER"), or ("") for the local computer.

(s) string-values: a tab-delimited or vertical-bar ('|') delimited list of string properties for the service being created. See below.

(s) numeric-values: a tab-delimited or vertical-bar ('|') delimited list of numeric properties for the service being created. See below.

(s) dependencies: a tab-delimited or vertical-bar ('|') delimited list of names of services or load ordering groups that must start before this service. Note: There should be no spaces around the delimiters.

(s) reserved: reserved for future use, and should be set to "".

Returns:

(i) always 1.

 

"string-values" is a is a tab-delimited or vertical-bar ('|') delimited list of string properties for the service being created, in the following format:

 

"ServiceName | DisplayName | BinaryPathName | LoadOrderGroup | ServiceStartName | Password"

 

(Spaces around the delimiters are permitted, but not necessary.)

 

ServiceName:

String that specifies the name of the service to install. The maximum string length is 256 characters. The service control manager database preserves the case of the characters, but service name comparisons are always case insensitive. Forward-slash (/) and back-slash (\) are invalid service name characters.

 

DisplayName:

String that is to be used by user interface programs to identify the service. This string has a maximum length of 256 characters. The name is case-preserved in the service control manager. Display name comparisons are always case-insensitive.

 

BinaryPathName:

The fully qualified path to the service binary file.

 

LoadOrderGroup:

The load ordering group of which this service is a member. If a blank string, the service does not belong to a group. The registry has a list of load ordering groups located at:

 

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ServiceGroupOrder

 

The startup program uses this list to load groups of services in a specified order with respect to the other groups in the list. You can place a service in a group so that another service can depend on the group. The order in which a service starts is determined by the following criteria:

 

1. The order of groups in the registry's load-ordering group list. Services in groups in the load-ordering group list are started first, followed by services in groups not in the load-ordering group list and then services that do not belong to a group.

 

2. The service's dependencies listed in the "Dependencies" parameter and the dependencies of other services dependent on the service.

 

ServiceStartName:

If the service type is SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS, this name is the account name in the form of "DomainName\Username", which the service process will be logged on as when it runs. If the account belongs to the built-in domain, ".\Username" can be specified. To log on as the LocalSystem account, specify "LocalSystem".

 

If the service type is SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER, this name is the Windows NT driver object name (that is, \FileSystem\Rdr or \Driver\Xns) which the input and output (I/O) system uses to load the device driver.

 

You can specify both a ServiceStartName and a Password together, in the form "ServiceStartName|Password". If ServiceStartName does not contain a '\', then '.\' will automatically be prepended, unless ServiceStartName == "LocalSystem".

 

 

Password:

Password to the account name specified by the "ServiceStartName" parameter if the service type is SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS. If the service type is SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER, this parameter is ignored.

 

"numeric-values" is a tab-delimited or vertical-bar ('|') delimited list of numeric properties for the service being created, in the following format:

 

"ServiceType | StartType | ErrorControl"

 

(Spaces around the delimiters are permitted, but not necessary.)

 

ServiceType:

Service type are the flags to indicate the type of service. In addition, for a SERVICE_WIN32 service, the SERVICE_INTERACTIVE_PROCESS flag might be set, indicating that the service process can interact with the desktop:

 

Value

Name

Meaning

1

SERVICE_KERNEL_DRIVER

Windows NT device driver.

2

SERVICE_FILE_SYSTEM_DRIVER

Windows NT file system driver.

16

SERVICE_WIN32_OWN_PROCESS

Win32 service that runs in its own process.

32

SERVICE_WIN32_SHARE_PROCESS

Win32 service that shares a process with other services.

 

In addition to the SERVICE_WIN32 service, the SERVICE_INTERACTIVE_PROCESS flag may be set, indicating that the service process can interact with the desktop:

Note: ServiceStartName must be LocalSystem in order to interact with the desktop.

 

256

SERVICE_INTERACTIVE_PROCESS

(Optional) Win32 service process that can interact with the desktop. Note: you must also specify a SERVICE_WIN32 service type.

 

StartType:

Specifies when to start the service. One of the following values is specified:

Value

Name

Meaning

0

SERVICE_BOOT_START

Device driver started by the operating system loader. This value is valid only if the service type is SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER.

1

SERVICE_SYSTEM_START

Device driver started by the IoInitSystem function. This value is valid only if the service type is SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER.

2

SERVICE_AUTO_START

Device driver or Win32 service started by the service control manager automatically during system startup.

3

SERVICE_DEMAND_START

Device driver or Win32 service started by the service control manager when a process calls the StartService function.

4

SERVICE_DISABLED

Device driver or Win32 service that can no longer be started.

 

ErrorControl:

Specifies the severity of the error if this service fails to start during startup, and determines the action taken by the startup program if failure occurs. One of the following values can be specified:

 

Value

Name

Meaning

0

SERVICE_ERROR_IGNORE

The startup (boot) program logs the error but continues the startup operation.

1

SERVICE_ERROR_NORMAL

The startup program logs the error and displays a message box pop-up but continues the startup operation.

2

SERVICE_ERROR_SEVERE

The startup program logs the error. If the last-known good configuration is being started, the startup operation continues. Otherwise, the system is restarted with the last-known-good configuration.

3

SERVICE_ERROR_CRITICAL

The startup program logs the error, if possible. If the last-known good configuration is being started, the startup operation fails. Otherwise, the system is restarted with the last-known good configuration.

 

Notes:

wntSvcCreate prepends '.\' to the specified ServiceStartName, if it doesn't already contain a contain a '\' (unless it's "LocalSystem").

A service that is running under the LocalSystem account cannot access network resources.

To have a service access the desktop, that service must log on as the LocalSystem account, and be allowed to interact with the desktop.

 

Example:
; Load Appropriate Extender
AddExtender('wwwnt34i.dll',0,'wwwnt64i.dll')

ServiceName="Computer Browser" DisplayName="Browser" BinaryPathName="d:\my share\browserservice.exe" LoadOrderGroup="" ServiceStartName="LocalSystem" Password="" createstring=StrCat(ServiceName,"|",DisplayName,"|",BinaryPathName,"|",LoadOrderGroup,"|",ServiceStartName,"|",Password) ServiceType=256|16 StartType=3 ErrorControl=0 createflags=StrCat(ServiceType,"|",StartType,"|",ErrorControl) wntSvcCreate("", createstring, createflags, "","") Message("Done","Added a service to the service control manager database.") Exit
See Also:

wntSvcCfgSet