| Previous | Main | End | Site Index | Download | Disclaimer | Privacy |


 

 

 

 

 

WINDOWS SERVICES: A SUPPLEMENTARY NOTE

 

 

 

 

 

 

Windows Service: Structures used in program examples of Windows Services 1 and Windows Services 2, where ever applicable. To learn about structure you can jump to struct, enum, typedef etc.

 

The Page Index

  1. SERVICE_STATUS

  2. SERVICE_TABLE_ENTRY

  3. STARTUPINFO

  4. QUERY_SERVICE_CONFIG

  5. QUERY_SERVICE_LOCK_STATUS

  6. ENUM_SERVICE_STATUS

  7. SERVICE_DESCRIPTION

  8. SERVICE_FAILURE_ACTIONS

  9. SC_ACTION

 

 

SERVICE_STATUS

 

Item

Description

Structure

SERVICE_STATUS.

Info

Contains information about a service. The ControlService(), EnumDependentServices(), EnumServicesStatus(), and QueryServiceStatus() functions use this structure to return information about a service. A service uses this structure in the SetServiceStatus() function to report its current status to the service control manager.

Definition

typedef struct _SERVICE_STATUS {

  DWORD dwServiceType;

  DWORD dwCurrentState;

  DWORD dwControlsAccepted;

  DWORD dwWin32ExitCode;

  DWORD dwServiceSpecificExitCode;

  DWORD dwCheckPoint;

  DWORD dwWaitHint;

} SERVICE_STATUS, *LPSERVICE_STATUS;

Members

See below.

Header file

<windows.h>

Remark

-

 

Table 1.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Members

 

dwServiceType - Type of service. This member can be one of the following values.

 

Value

Meaning

SERVICE_FILE_SYSTEM_DRIVER

The service is a file system driver.

SERVICE_KERNEL_DRIVER

The service is a device driver.

SERVICE_WIN32_OWN_PROCESS

The service runs in its own process.

SERVICE_WIN32_SHARE_PROCESS

The service shares a process with other services.

 

Table 2

 

If the service type is either SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS, and the service is running in the context of the LocalSystem account, the following type may also be specified.

 

Value

Meaning

SERVICE_INTERACTIVE_PROCESS

The service can interact with the desktop.

 

Table 3

 

dwCurrentState - Current state of the service. This member can be one of the following values.

 

Value

Meaning

SERVICE_CONTINUE_PENDING

The service continue is pending.

SERVICE_PAUSE_PENDING

The service pause is pending.

SERVICE_PAUSED

The service is paused.

SERVICE_RUNNING

The service is running.

SERVICE_START_PENDING

The service is starting.

SERVICE_STOP_PENDING

The service is stopping.

SERVICE_STOPPED

The service is not running.

 

Table 4

 

dwControlsAccepted - Control codes the service accepts and processes in its handler function (Handler() and HandlerEx()). A user interface process can control a service by specifying a control command in the ControlService() function. By default, all services accept the SERVICE_CONTROL_INTERROGATE value. The following are the control codes.

 

Control code

Meaning

SERVICE_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 SERVICE_CONTROL_NETBINDADD, SERVICE_CONTROL_NETBINDREMOVE, SERVICE_CONTROL_NETBINDENABLE, and SERVICE_CONTROL_NETBINDDISABLE notifications. For Windows NT:  This value is not supported.

SERVICE_ACCEPT_PARAMCHANGE

The service can reread its startup parameters without being stopped and restarted. This control code allows the service to receive SERVICE_CONTROL_PARAMCHANGE notifications. For Windows NT:  This value is not supported.

SERVICE_ACCEPT_PAUSE_CONTINUE

The service can be paused and continued.

This control code allows the service to receive SERVICE_CONTROL_PAUSE and SERVICE_CONTROL_CONTINUE notifications.

SERVICE_ACCEPT_SHUTDOWN

The service is notified when system shutdown occurs.

This control code allows the service to receive SERVICE_CONTROL_SHUTDOWN notifications. Note that ControlService() cannot send this notification; only the system can send it.

SERVICE_ACCEPT_STOP

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

 

Table 5

 

This value can also contain the following extended control codes, which are supported only by HandlerEx().

 

Control code

Meaning

SERVICE_ACCEPT_HARDWAREPROFILECHANGE

The service is notified when the computer's hardware profile has changed. This enables the system to send SERVICE_CONTROL_HARDWAREPROFILECHANGE notifications to the service. For Windows NT:  This value is not supported.

SERVICE_ACCEPT_POWEREVENT

The service is notified when the computer's power status has changed. This enables the system to send SERVICE_CONTROL_POWEREVENT notifications to the service. For Windows NT:  This value is not supported.

SERVICE_ACCEPT_SESSIONCHANGE

The service is notified when the computer's session status has changed. This enables the system to send SERVICE_CONTROL_SESSIONCHANGE notifications to the service. For Windows 2000/NT:  This value is not supported.

 

Table 6

 

dwWin32ExitCode - 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 dwServiceSpecificExitCode member contains the error code. The service should set this value to NO_ERROR when it is running and on normal termination. dwServiceSpecificExitCode - 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 dwWin32ExitCode member is set to ERROR_SERVICE_SPECIFIC_ERROR. dwCheckPoint - 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. dwWaitHint - 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 dwCurrentState. If the amount of time specified by dwWaitHint passes, and dwCheckPoint has not been incremented or dwCurrentState has not changed, the service control manager or service control program can assume that an error has occurred and the service should be stopped.

 

SERVICE_TABLE_ENTRY

 

Item

Description

Structure

SERVICE_TABLE_ENTRY.

Info

Is used by the StartServiceCtrlDispatcher() function to specify the ServiceMain() function for a service that can run in the calling process.

Definition

typedef struct _SERVICE_TABLE_ENTRY {

  LPTSTR lpServiceName;

  LPSERVICE_MAIN_FUNCTION lpServiceProc;

} SERVICE_TABLE_ENTRY, *LPSERVICE_TABLE_ENTRY;

Members

lpServiceName - Pointer to a null-terminated string that specifies the name of a service to be run in this service process. This string is ignored if the service is installed in the service control manager database as a SERVICE_WIN32_OWN_PROCESS service type. For a SERVICE_WIN32_SHARE_PROCESS service process, this string names the service that uses the ServiceMain() function pointed to by the lpServiceProc member.

lpServiceProc - Pointer to a ServiceMain() function.

Header file

<windows.h>

Remark

Declared as Unicode and ANSI structures.

 

Table 7.

 

STARTUPINFO

 

Item

Description

Structure

STARTUPINFO.

Info

Is used with the CreateProcess(), CreateProcessAsUser(), and CreateProcessWithLogonW() functions to specify the window station, desktop, standard handles, and appearance of the main window for the new process.

Definition

typedef struct _STARTUPINFO {

  DWORD cb;

  LPTSTR lpReserved;

  LPTSTR lpDesktop;

  LPTSTR lpTitle;

  DWORD dwX;

  DWORD dwY;

  DWORD dwXSize;

  DWORD dwYSize;

  DWORD dwXCountChars;

  DWORD dwYCountChars;

  DWORD dwFillAttribute;

  DWORD dwFlags;

  WORD wShowWindow;

  WORD cbReserved2;

  LPBYTE lpReserved2;

  HANDLE hStdInput;

  HANDLE hStdOutput;

  HANDLE hStdError;

} STARTUPINFO, *LPSTARTUPINFO;

Members

See below.

Header file

<windows.h>

Remark

Declared as Unicode and ANSI structures. For graphical user interface (GUI) processes, this information affects the first window created by the CreateWindow() function and shown by the ShowWindow() function. For console processes, this information affects the console window if a new console is created for the process. A process can use the GetStartupInfo() function to retrieve the STARTUPINFO structure specified when the process was created. If a GUI process is being started and neither STARTF_FORCEONFEEDBACK or STARTF_FORCEOFFFEEDBACK is specified, the process feedback cursor is used. A GUI process is one whose subsystem is specified as "windows."

 

Table 8.

 

Members

 

cb - Size of the structure, in bytes.

lpReserved - Reserved. Set this member to NULL before passing the structure to CreateProcess().

lpDesktop - Pointer to a null-terminated string that specifies either the name of the desktop or the name of both the desktop and window station for this process. A backslash in the string indicates that the string includes both the desktop and window station names. For CreateProcess() and CreateProcessAsUser(), if this member is NULL, the new process inherits the desktop and window station of its parent process. If this member is an empty string, the process does not inherit the desktop and window station of its parent process; instead, the system determines if a new desktop and window station need to be created. If the impersonated user already has a desktop, the system uses the existing desktop. For CreateProcessWithLogonW(), if this member is NULL or an empty string, the new process inherits the desktop and window station of its parent process. It is the responsibility of the application to add permission for the specified user account to the inherited window station and desktop, even for WinSta0\Default. Windows Me/98/95:  Desktops and window stations are not supported.

lpTitle - For console processes, this is the title displayed in the title bar if a new console window is created. If NULL, the name of the executable file is used as the window title instead. This parameter must be NULL for GUI or console processes that do not create a new console window.

dwX - If dwFlags specifies STARTF_USEPOSITION, this member is the x offset of the upper left corner of a window if a new window is created, in pixels. Otherwise, this member is ignored. The offset is from the upper left corner of the screen. For GUI processes, the specified position is used the first time the new process calls CreateWindow() to create an overlapped window if the x parameter of CreateWindow() is CW_USEDEFAULT.

dwY - If dwFlags specifies STARTF_USEPOSITION, this member is the y offset of the upper left corner of a window if a new window is created, in pixels. Otherwise, this member is ignored. The offset is from the upper left corner of the screen. For GUI processes, the specified position is used the first time the new process calls CreateWindow() to create an overlapped window if the y parameter of CreateWindow() is CW_USEDEFAULT.

dwXSize - If dwFlags specifies STARTF_USESIZE, this member is the width of the window if a new window is created, in pixels. Otherwise, this member is ignored. For GUI processes, this is used only the first time the new process calls CreateWindow() to create an overlapped window if the nWidth parameter of CreateWindow() is CW_USEDEFAULT.

dwYSize - If dwFlags specifies STARTF_USESIZE, this member is the height of the window if a new window is created, in pixels. Otherwise, this member is ignored. For GUI processes, this is used only the first time the new process calls CreateWindow() to create an overlapped window if the nHeight parameter of CreateWindow() is CW_USEDEFAULT.

dwXCountChars - If dwFlags specifies STARTF_USECOUNTCHARS, if a new console window is created in a console process, this member specifies the screen buffer width, in character columns. Otherwise, this member is ignored.

dwYCountChars - If dwFlags specifies STARTF_USECOUNTCHARS, if a new console window is created in a console process, this member specifies the screen buffer height, in character rows. Otherwise, this member is ignored.

dwFillAttribute - If dwFlags specifies STARTF_USEFILLATTRIBUTE, this member is the initial text and background colors if a new console window is created in a console application. Otherwise, this member is ignored. This value can be any combination of the following values:

FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY

For example, the following combination of values produces red text on a white background:

 

FOREGROUND_RED| BACKGROUND_RED| BACKGROUND_GREEN| BACKGROUND_BLUE

 

dwFlags - Bit field that determines whether certain STARTUPINFO members are used when the process creates a window. This member can be one or more of the following values.

 

Value

Meaning

STARTF_FORCEONFEEDBACK

Indicates that the cursor is in feedback mode for two seconds after CreateProcess() is called. The Working in Background cursor is displayed (see the Pointers tab in the Mouse control panel utility). If during those two seconds the process makes the first GUI call, the system gives five more seconds to the process. If during those five seconds the process shows a window, the system gives five more seconds to the process to finish drawing the window. The system turns the feedback cursor off after the first call to GetMessage(), regardless of whether the process is drawing.

STARTF_FORCEOFFFEEDBACK

Indicates that the feedback cursor is forced off while the process is starting. The Normal Select cursor is displayed.

STARTF_RUNFULLSCREEN

Indicates that the process should be run in full-screen mode, rather than in windowed mode. This flag is only valid for console applications running on an x86 computer. For Windows Me/98/95:  This value is not supported.

STARTF_USECOUNTCHARS

If this value is not specified, the dwXCountChars and dwYCountChars members are ignored. For Windows Me/98/95:  This value is not supported.

STARTF_USEFILLATTRIBUTE

If this value is not specified, the dwFillAttribute member is ignored.

STARTF_USEPOSITION

If this value is not specified, the dwX and dwY members are ignored.

STARTF_USESHOWWINDOW

If this value is not specified, the wShowWindow member is ignored.

STARTF_USESIZE

If this value is not specified, the dwXSize and dwYSize members are ignored.

STARTF_USESTDHANDLES

Sets the standard input, standard output, and standard error handles for the process to the handles specified in the hStdInput, hStdOutput, and hStdError members of the STARTUPINFO structure. For this to work properly, the handles must be inheritable and the CreateProcess() function's bInheritHandles parameter must be set to TRUE. If this value is not specified, the hStdInput, hStdOutput, and hStdError members of the STARTUPINFO structure are ignored.

 

Table 9

 

wShowWindow - If dwFlags specifies STARTF_USESHOWWINDOW, this member can be any of the SW_ constants defined in Winuser.h. Otherwise, this member is ignored. For GUI processes, wShowWindow specifies the default value the first time ShowWindow() is called. The nCmdShow parameter of ShowWindow() is ignored. In subsequent calls to ShowWindow(), the wShowWindow member is used if the nCmdShow parameter of ShowWindow() is set to SW_SHOWDEFAULT.

cbReserved2 - Reserved for use by the C Runtime; must be zero.

lpReserved2 - Reserved for use by the C Runtime; must be NULL.

hStdInput - If dwFlags specifies STARTF_USESTDHANDLES, this member is a handle to be used as the standard input handle for the process. Otherwise, this member is ignored.

hStdOutput - If dwFlags specifies STARTF_USESTDHANDLES, this member is a handle to be used as the standard output handle for the process. Otherwise, this member is ignored.

hStdError - If dwFlags specifies STARTF_USESTDHANDLES, this member is a handle to be used as the standard error handle for the process. Otherwise, this member is ignored.

 

QUERY_SERVICE_CONFIG

 

Item

Description

Structure

QUERY_SERVICE_CONFIG.

Info

Is used by the QueryServiceConfig() function to return configuration information about an installed service.

Definition

typedef struct _QUERY_SERVICE_CONFIG {

  DWORD dwServiceType;

  DWORD dwStartType;

  DWORD dwErrorControl;

  LPTSTR lpBinaryPathName;

  LPTSTR lpLoadOrderGroup;

  DWORD dwTagId;

  LPTSTR lpDependencies;

  LPTSTR lpServiceStartName;

  LPTSTR lpDisplayName;

} QUERY_SERVICE_CONFIG, *LPQUERY_SERVICE_CONFIG;

Members

See below.

Header file

<windows.h>

Remark

Declared as Unicode and ANSI structures. The configuration information for a service is initially specified when the service is created by a call to the CreateService() function. The information can be modified by calling the ChangeServiceConfig() function.

 

Table 10.

 

 

Members

 

dwServiceType - Type of service. This member can be one of the following values.

 

Value

Meaning

SERVICE_FILE_SYSTEM_DRIVER

File system driver service.

SERVICE_KERNEL_DRIVER

Driver service.

SERVICE_WIN32_OWN_PROCESS

Service that runs in its own process.

SERVICE_WIN32_SHARE_PROCESS

Service that shares a process with other services.

 

Table 11

 

If the value is SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS, and the service is running in the context of the LocalSystem account, the following type may also be specified.

 

Value

Meaning

SERVICE_INTERACTIVE_PROCESS

The service can interact with the desktop.

 

Table 12

 

dwStartType - When to start the service. This member can be one of the following values.

 

Value

Meaning

SERVICE_AUTO_START

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

SERVICE_BOOT_START

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

SERVICE_DEMAND_START

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

SERVICE_DISABLED

A service that cannot be started. Attempts to start the service result in the error code ERROR_SERVICE_DISABLED.

SERVICE_SYSTEM_START

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

 

Table 13

 

dwErrorControl - Severity of the error, and action taken, if this service fails to start. This member can be one of the following values.

 

Value

Meaning

SERVICE_ERROR_IGNORE

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

SERVICE_ERROR_NORMAL

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

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.

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.

 

Table 14

 

lpBinaryPathName - Pointer to a null-terminated string that contains the fully qualified path to the service binary file. The path can also include arguments for an auto-start service. These arguments are passed to the service entry point (typically the main function).

lpLoadOrderGroup - Pointer to a null-terminated string that names the load ordering group to which this service belongs. If the member is NULL or an empty string, the service does not belong to a load ordering group. The startup program uses load ordering groups to load groups of services in a specified order with respect to the other groups. The list of load ordering groups is contained in the following registry value:

 

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ServiceGroupOrder

 

dwTagId - Unique tag value for this service in the group specified by the lpLoadOrderGroup parameter. A value of zero indicates that the service has not been assigned a tag. You can use a tag for ordering service startup within a load order group by specifying a tag order vector in the registry located at:

 

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\GroupOrderList

 

Tags are only evaluated for SERVICE_KERNEL_DRIVER and SERVICE_FILE_SYSTEM_DRIVER type services that have SERVICE_BOOT_START or SERVICE_SYSTEM_START start types.

lpDependencies - Pointer to an array of null-separated names of services or load ordering groups that must start before this service. The array is doubly null-terminated. If the pointer is NULL or if it points to an empty string, the service has no dependencies. If a group name is specified, it must be prefixed by the SC_GROUP_IDENTIFIER (defined in Winsvc.h) character to differentiate it from a service name, because services and service groups share the same name space. Dependency on a service means that this service can only run if the service it depends on is running. Dependency on a group means that this service can run if at least one member of the group is running after an attempt to start all members of the group.

lpServiceStartName - Pointer to a null-terminated string. 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. If this member is NULL, the service is to be logged on as the LocalSystem account. Windows XP:  If this member is NT AUTHORITY\LocalService, CreateService() uses the LocalService account. If the parameter is NT AUTHORITY\NetworkService, CreateService() uses the NetworkService account. If the service type is SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER, this name is the driver object name (that is, \FileSystem\Rdr or \Driver\Xns) which the input and output (I/O) system uses to load the device driver. If this member is NULL, the driver is to be run with a default object name created by the I/O system, based on the service name.

lpDisplayName - Pointer to a null-terminated string that specifies the display name to be used by service control 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.

 

QUERY_SERVICE_LOCK_STATUS

 

Item

Description

Structure

QUERY_SERVICE_LOCK_STATUS.

Info

Is used by the QueryServiceLockStatus() function to return information about the lock status of a service control manager database.

Definition

typedef struct _QUERY_SERVICE_LOCK_STATUS {

  DWORD fIsLocked;

  LPTSTR lpLockOwner;

  DWORD dwLockDuration;

} QUERY_SERVICE_LOCK_STATUS, *LPQUERY_SERVICE_LOCK_STATUS;

Members

fIsLocked - Lock status of the database. If this member is nonzero, the database is locked. If it is zero, the database is unlocked.

lpLockOwner - Pointer to a null-terminated string containing the name of the user who acquired the lock.

dwLockDuration - Time since the lock was first acquired, in seconds.

Header file

<windows.h>

Remark

Declared as Unicode and ANSI structures.

 

Table 15.

 

ENUM_SERVICE_STATUS

 

Item

Description

Structure

ENUM_SERVICE_STATUS.

Info

Is used by the EnumDependentServices() and EnumServicesStatus() functions to return the name of a service in a service control manager database and to return information about that service.

Definition

typedef struct _ENUM_SERVICE_STATUS {

  LPTSTR lpServiceName;

  LPTSTR lpDisplayName;

  SERVICE_STATUS ServiceStatus;

} ENUM_SERVICE_STATUS, *LPENUM_SERVICE_STATUS;

Members

lpServiceName - Pointer to a null-terminated string that specifies the name of a service in the service control manager database. 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. A slash (/), backslash (\), comma, and space are invalid service name characters.

lpDisplayName - Pointer to a null-terminated string that specifies a display name that can be used by service control programs, such as Services in Control Panel, 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.

ServiceStatus - A SERVICE_STATUS structure that contains status information for the lpServiceName service.

Header file

<windows.h>

Remark

Declared as Unicode and ANSI structures.

 

Table 16.

 

SERVICE_DESCRIPTION

 

Item

Description

Structure

SERVICE_DESCRIPTION.

Info

Represents a service description.

Definition

typedef struct _SERVICE_DESCRIPTION {

  LPTSTR lpDescription;

} SERVICE_DESCRIPTION, *LPSERVICE_DESCRIPTION;

Members

lpDescription - Pointer to a null-terminated string that specifies the description of the service. If this value is NULL, the description remains unchanged. If this value is an empty string (""), the current description is deleted. The service description must not exceed the size of a registry value of type REG_SZ.

Header file

<windows.h>

Remark

Declared as Unicode and ANSI structures. A description of NULL indicates no service description exists. The service description is NULL when the service is created. The description is simply a comment that explains the purpose of the service. For example, for the DHCP service, you could use the description "Provides internet addresses for computer on your network." You can set the description using the ChangeServiceConfig2() function. You can retrieve the description using the QueryServiceConfig2() function. The description is also displayed by the Services snap-in.

 

Table 17.

 

SERVICE_FAILURE_ACTIONS

 

Item

Description

Structure

SERVICE_FAILURE_ACTIONS.

Info

Represents the action the service controller should take on each failure of a service. A service is considered failed when it terminates without reporting a status of SERVICE_STOPPED to the service controller.

Definition

typedef struct _SERVICE_FAILURE_ACTIONS {

  DWORD dwResetPeriod;

  LPTSTR lpRebootMsg;

  LPTSTR lpCommand;

  DWORD cActions;

  SC_ACTION* lpsaActions;

} SERVICE_FAILURE_ACTIONS, *LPSERVICE_FAILURE_ACTIONS;

Members

dwResetPeriod - Time after which to reset the failure count to zero if there are no failures, in seconds. Specify INFINITE to indicate that this value should never be reset.

lpRebootMsg - Message to broadcast to server users before rebooting in response to the SC_ACTION_REBOOT service controller action. If this value is NULL, the reboot message is unchanged. If the value is an empty string (""), the reboot message is deleted and no message is broadcast.

lpCommand - Command line of the process for the CreateProcess() function to execute in response to the SC_ACTION_RUN_COMMAND service controller action. This process runs under the same account as the service. If this value is NULL, the command is unchanged. If the value is an empty string (""), the command is deleted and no program is run when the service fails.

cActions - Number of elements in the lpsaActions array. If this value is 0, but lpsaActions is not NULL, the reset period and array of failure actions are deleted.

lpsaActions - Pointer to an array of SC_ACTION structures. If this value is NULL, the cActions and dwResetPeriod members are ignored.

Header file

<windows.h>

Remark

Declared as Unicode and ANSI structures. The service control manager counts the number of times each service has failed since the system booted. The count is reset to 0 if the service has not failed for dwResetPeriod seconds. When the service fails for the Nth time, the service controller performs the action specified in element [N-1] of the lpsaActions array. If N is greater than cActions, the service controller repeats the last action in the array.

 

Table 18.

 

SC_ACTION

 

Item

Description

Structure

SC_ACTION.

Info

Represents an action that the service control manager can perform.

Definition

typedef struct _SC_ACTION {

  SC_ACTION_TYPE Type;

  DWORD Delay;

} SC_ACTION, *LPSC_ACTION;

Members

See below.

Header file

<windows.h>

Remark

This structure is used by the ChangeServiceConfig2() and QueryServiceConfig2() functions, in the SERVICE_FAILURE_ACTIONS structure.

 

Table 19.

 

Members

 

Type - Action to be performed. This member can be one of the following values.

 

Value

Meaning

SC_ACTION_NONE

No action.

SC_ACTION_REBOOT

Reboot the computer.

SC_ACTION_RESTART

Restart the service.

SC_ACTION_RUN_COMMAND

Run a command.

 

Table 20

 

Delay - Time to wait before performing the specified action, in milliseconds.

 

 

-----------------------------------------End Windows Services Structures---------------------------------------

 

 

 

 

 

 

Further reading and digging:

 

  1. Microsoft Visual C++, online MSDN.

  2. Structure, enum, union and typedef story can be found at C enum, typedef, define etc..

  3. For Multibytes, Unicode characters and Localization please refer to Unicode & Multibyte 1 (Story) and Unicode & Multibyte 2 (Implementation).

  4. Windows data type information is in Windows data type.

  5. Check the best selling C / C++ and Windows books at Amazon.com.

 

 

 

 

 

| Previous | Main | End | Site Index | Download | Disclaimer | Privacy |