Service.Create

Service.Create ( 

string  Filename,

string  DisplayName = "Service1",

string  KeyName = "",

number  ServiceType = SERVICE_WIN32_OWN_PROCESS,

boolean AllowDesktopInteraction = false,

number  StartType = SERVICE_DEMAND_START,

number  ErrorControl = SERVICE_ERROR_NORMAL,

string  LoadOrderGroup = "",

number  GroupTag = nil,

table   Dependencies = nil,

string  ServiceStartName = "",

string  Password = "" )

Description

Creates a new service on the local system.

Parameters

Filename

(string) The fully qualified path to the service binary file, with or without arguments.

DisplayName

(string) A string that user interface programs will use to identify the service.

KeyName

(number) A string that names the service to install. The maximum string length is 256 characters to be a valid Windows key name.

Note: 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.

ServiceType

(number) The type of service. This can be one of the following:

CONSTANT

VALUE

DESCRIPTION

SERVICE_WIN32_OWN_PROCESS

0

Service that runs in its own process.

SERVICE_WIN32_SHARE_PROCESS

1

Service that shares a process with other services.

SERVICE_KERNEL_DRIVER

2

Driver service.

SERVICE_FILE_SYSTEM_DRIVER

3

File system driver service.

AllowDesktopInteraction

(boolean) Whether to allow the service process to interact with the desktop. If set to true, the service must run in the "LocalSystem" account. This can be done by setting the ServiceStartName to "LocalSystem".

StartType

(number) The way in which the service will be started. This can be one of the following:

CONSTANT

VALUE

DESCRIPTION

SERVICE_BOOT_START

0

A device driver started by the system loader. This value is valid only for driver services.

SERVICE_SYSTEM_START

1

A device driver started by the IoInitSystem function. This value is valid only for driver services.

SERVICE_AUTO_START

2

A service started automatically by the service control manager during system startup.

SERVICE_DEMAND_START

3

A service started by the service control manager when a process calls the StartService function.

SERVICE_DISABLED

4

A service that cannot be started. Attempts to start this service will result in a Windows error.

ErrorControl

(number) The severity of the error if this service fails to start during startup. Can be one of the following:

CONSTANT

VALUE

DESCRIPTION

SERVICE_ERROR_IGNORE

0

The startup program logs the error but continues the startup operation.

SERVICE_ERROR_NORMAL

1

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

SERVICE_ERROR_SEVERE

2

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.

SERVICE_ERROR_CRITICAL

3

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.

LoadOrderGroup

(string) The name of the load ordering group of which this service is a member. Enter an empty string "" if it does not belong to a group.

GroupTag

(number) The tag value. This value is unique to the load order group. Tags are only evaluated for driver services that have SERVICE_BOOT_START or SERVICE_SYSTEM_START start types.

Dependencies

(table) A numerically indexed table containing the names of services or load order groups that must be loaded before this service can start.

ServiceStartName

(string) A string that names the account under which the service should run. If the service type is SERVICE_WIN32_OWN_PROCESS, use an account name in the form "DomainName\\UserName". The service process will be logged on as this user. If the account belongs to the built-in domain, you can specify ".\\UserName". If this parameter is empty (""), the service create uses the LocalSystem account. If the AllowDesktopInteraction option is set to true, the service must run in the "LocalSystem" account.

Password

(string) The password for the service. Specify an empty string "" if the account has no password or if the service runs in the LocalService, NetworkService, or LocalSystem account. Passwords are ignored for driver services.

Returns

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

See also:  Related Actions