Creating a windows service

create_service()

Create a Windows service


SYNTAX

create_service(manager_handle, service_name, display_name, description, pathname, \

   dependencies, account_name, password, access_rights, service_type, start_type, error_control)

Creates a Windows service and adds it to the service control manager database. See CreateService() in the Windows API.

manager_handle

A handle obtained by a previous call to open_scmanager().

service_name

Internal name for the service. Cannot include the slash (/) or backslash (\) character.

display_name

Display name for the service in Windows Service Manager.

description

A short description of the service. Can be a null string.

pathname

Full path to the executable program. If the name contains a space it must be quoted. Arguments may follow the name.

dependencies

The service names of other services upon which this service depends. Separate each name with a comma and avoid spaces. If this service has no dependencies, supply a null string.

account_name

The name of the account under which the service is to run. If a null string is supplied, the service runs in the LocalSystem account. Other standard accounts are:

“NT_AUTHORITY\\LocalService”
“NT_AUTHORITY\\NetworkService”

The double backslash ( \\ ) is needed because \ is an escape character in Sculptor string constants. It becomes a single \ in the compiled program.

password

The password for the specified account. Supply a null string if the account has no password or the service runs in the LocalSystem, LocalService or NetworkService account.

access_rights

Desired access to the service. See the Windows API for full details. SERVICE_ALL_ACCESS can be used if the user running the program has Administrator privileges.

service_type

One of the following:

SERVICE_FILE_SYSTEM_DRIVER
SERVICE_KERNEL_DRIVER
SERVICE_WIN32_OWN_PROCESS
SERVICE_WIN32_SHARE_PROCESS

start_type

One of the following:

SERVICE_AUTO_START

Start during system startup.

SERVICE_BOOT_START

Start by loader (drivers).

SERVICE_DEMAND_START

Started by StartService().

SERVICE_DISABLED

Cannot be started.

SERVICE_SYSTEM_START

Started by IoInitSystem().

error_control

One of the following:

SERVICE_ERROR_CRITICAL

Fail if last good or restart

SERVICE_ERROR_IGNORE

Log error, continue startup

SERVICE_ERROR_NORMAL

Log error, message box.

SERVICE_ERROR_SEVERE

Continue if last good or restart.

If successful the function returns a service handle, which should be stored in an i8 type field.

It returns 0 if the service cannot be created. The Windows error code is stored in sys.Errno.


RELATED TOPICS

Servers

Windows service management functions