Win32-services-0.2.5.1: Windows service applications

Safe HaskellSafe
LanguageHaskell2010

System.Win32.SystemServices.Services

Synopsis

Documentation

type HandlerFunction = HANDLE -> SERVICE_CONTROL -> IO Bool Source

A handler function is registered with the service dispatcher thread from a ServiceMainFunction. The first argument is a HANDLE returned from calling registerServiceCtrlHandler. The second argument represents the command this service has been directed to perform.

type ServiceMainFunction = String -> [String] -> HANDLE -> IO () Source

The service dispatcher thread will call each function of this type that you provide. The first argument will be the name of the service. Any additional command-line parameters will appear in the second argument.

Each of these functions should call registerServiceCtrlHandler to register a function to handle incoming commands. It should then set the service's status to START_PENDING, and specify that no controls will be accepted. At this point the function may perform any other initialization steps before setting the service's status to RUNNING. All of this should take no more than 100ms.

data SERVICE_ACCEPT Source

The control codes the service accepts and processes in its handler function (See HandlerFunction). By default, all services accept the INTERROGATE value. To accept the DEVICEEVENT value, the service must register to receive device events by using the registerDeviceNotification function.

Constructors

ACCEPT_NETBINDCHANGE

The service is a network component that can accept changes in its binding without being stopped and restarted. This control code allows the service to receive NETBINDADD, NETBINDREMOVE, NETBINDENABLE, and NETBINDDISABLE notifications.

ACCEPT_PARAMCHANGE

The service can reread its startup parameters without being stopped and restarted. This control code allows the service to receive PARAMCHANGE notifications.

ACCEPT_PAUSE_CONTINUE

The service can be paused and continued. This control code allows the service to receive PAUSE and CONTINUE notifications.

ACCEPT_PRESHUTDOWN

MSDN documentation says that this function is not supported on Windows Server 2003 or Windows XP/2000. The support status on other versions is unknown to me.

The service can perform preshutdown tasks. This control code enables the service to receive PRESHUTDOWN notifications. Note that only the system can send it.

ACCEPT_SHUTDOWN

The service is notified when system shutdown occurs. This control code allows the service to receive SHUTDOWN notifications. Note that only the system can send it.

ACCEPT_STOP

The service can be stopped. This control code allows the service to receive STOP notifications.

data SERVICE_CONTROL Source

A SERVICE_CONTROL is used in Handler functions. All control codes are defined here, but some can only be used with a HandlerEx callback. Use convertSuccess to translate from a SERVICE_CONTROL to a DWORD. Use convertAttempt to translate from a DWORD to a SERVICE_CONTROL.

data SERVICE_STATUS Source

Contains status information for a service.

Constructors

SERVICE_STATUS 

Fields

serviceType :: SERVICE_TYPE

The type of service. This binding only supports the WIN32_OWN_PROCESS type.

currentState :: SERVICE_STATE

The current state of the service.

controlsAccepted :: [SERVICE_ACCEPT]

See SERVICE_ACCEPT for details on this field.

win32ExitCode :: DWORD

The error code the service uses to report an error that occurs when it is starting or stopping. To return an error code specific to the service, the service must set this value to eRROR_SERVICE_SPECIFIC_ERROR to indicate that the serviceSpecificExitCode member contains the error code. The service should set this value to nO_ERROR when it is running and on normal termination.

serviceSpecificExitCode :: DWORD

A service-specific error code that the service returns when an error occurs while the service is starting or stopping. This value is ignored unless the win32ExitCode member is set to eRROR_SERVICE_SPECIFIC_ERROR.

This binding does not support service-specific error codes.

checkPoint :: DWORD

The check-point value the service increments periodically to report its progress during a lengthy start, stop, pause, or continue operation. For example, the service should increment this value as it completes each step of its initialization when it is starting up. The user interface program that invoked the operation on the service uses this value to track the progress of the service during a lengthy operation. This value is not valid and should be zero when the service does not have a start, stop, pause, or continue operation pending.

waitHint :: DWORD

The estimated time required for a pending start, stop, pause, or continue operation, in milliseconds. Before the specified amount of time has elapsed, the service should make its next call to the SetServiceStatus function with either an incremented dwCheckPoint value or a change in currentState. If the amount of time specified by waitHint passes, and checkPoint has not been incremented or currentState has not changed, the service control manager or service control program can assume that an error has occurred and the service should be stopped. However, if the service shares a process with other services, the service control manager cannot terminate the service application because it would have to terminate the other services sharing the process as well.

data SERVICE_TYPE Source

Win32 defines many types of services, but this binding only supports WIN32_OWN_PROCESS.

Constructors

FILE_SYSTEM_DRIVER

The service is a file system driver.

KERNEL_DRIVER

The service is a device driver.

WIN32_OWN_PROCESS

The service runs in its own process.

WIN32_SHARE_PROCESS

The service shares a process with other services.

SERVICE_INTERACTIVE_PROCESS

Do no write your own services of this type. Windows Vista and above prevent service processes from directly interacting with users.

A SERVICE_INTERACTIVE_PROCESS is either a WIN32_OWN_PROCESS or a WIN32_SHARE_PROCESS running in the context of the LocalSystem account which is allowed to directly interact with users.

queryServiceStatus Source

Arguments

:: HANDLE

MSDN documentation: A handle to the service. This handle is returned by the OpenService or the CreateService function, and it must have the SERVICE_QUERY_STATUS access right. For more information, see Service Security and Access Rights.

-> IO SERVICE_STATUS

This function will raise an exception if the Win32 call returned an error condition.

Retrieves the current status of the specified service.

setServiceStatus Source

Arguments

:: HANDLE

MSDN documentation: A handle to the status information structure for the current service. This handle is returned by the RegisterServiceCtrlHandlerEx function.

-> SERVICE_STATUS

MSDN documentation: A pointer to the SERVICE_STATUS structure the contains the latest status information for the calling service.

-> IO ()

This function will raise an exception if the Win32 call returned an error condition.

Updates the service control manager's status information for the calling service.

startServiceCtrlDispatcher Source

Arguments

:: String

The name of the service. According to MSDN documentation this argument is unused in WIN32_OWN_PROCESS type services, which is the only type supported by this binding. Even so, it is recommended that the name of the service be used.

MSDN description: The name of the service run by the calling thread. This is the service name that the service control program specified in the CreateService function when creating the service.

-> DWORD
waitHint
The estimated time required for a pending start, stop, pause, or continue operation, in milliseconds.
-> HandlerFunction 
-> ServiceMainFunction

This is a callback function that will be called by the operating system whenever the service is started. It should perform service initialization including the registration of a handler function. MSDN documentation gives conflicting advice as to whether this function should return before the service has entered the stopped state. In the official example the service main function blocks until the service is ready to stop.

-> IO ()

An exception will be raised if the underlying Win32 call returns an error condition.

Register a callback function to initialize the service, which will be called by the operating system immediately. startServiceCtrlDispatcher will block until the provided callback function returns.

MSDN documentation: Connects the main thread of a service process to the service control manager, which causes the thread to be the service control dispatcher thread for the calling process.