QueryServiceConfig2W function (winsvc.h)

Retrieves the optional configuration parameters of the specified service.

Syntax

BOOL QueryServiceConfig2W(
  [in]            SC_HANDLE hService,
  [in]            DWORD     dwInfoLevel,
  [out, optional] LPBYTE    lpBuffer,
  [in]            DWORD     cbBufSize,
  [out]           LPDWORD   pcbBytesNeeded
);

Parameters

[in] hService

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

[in] dwInfoLevel

The configuration information to be queried. This parameter can be one of the following values.

Value Meaning
SERVICE_CONFIG_DELAYED_AUTO_START_INFO
3
The lpInfo parameter is a pointer to a SERVICE_DELAYED_AUTO_START_INFO structure.

Windows Server 2003 and Windows XP:  This value is not supported.

SERVICE_CONFIG_DESCRIPTION
1
The lpBuffer parameter is a pointer to a SERVICE_DESCRIPTION structure.
SERVICE_CONFIG_FAILURE_ACTIONS
2
The lpBuffer parameter is a pointer to a SERVICE_FAILURE_ACTIONS structure.
SERVICE_CONFIG_FAILURE_ACTIONS_FLAG
4
The lpInfo parameter is a pointer to a SERVICE_FAILURE_ACTIONS_FLAG structure.

Windows Server 2003 and Windows XP:  This value is not supported.

SERVICE_CONFIG_PREFERRED_NODE
9
The lpInfo parameter is a pointer to a SERVICE_PREFERRED_NODE_INFO structure.

Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP:  This value is not supported.

SERVICE_CONFIG_PRESHUTDOWN_INFO
7
The lpInfo parameter is a pointer to a SERVICE_PRESHUTDOWN_INFO structure.

Windows Server 2003 and Windows XP:  This value is not supported.

SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO
6
The lpInfo parameter is a pointer to a SERVICE_REQUIRED_PRIVILEGES_INFO structure.

Windows Server 2003 and Windows XP:  This value is not supported.

SERVICE_CONFIG_SERVICE_SID_INFO
5
The lpInfo parameter is a pointer to a SERVICE_SID_INFO structure.

Windows Server 2003 and Windows XP:  This value is not supported.

SERVICE_CONFIG_TRIGGER_INFO
8
The lpInfo parameter is a pointer to a SERVICE_TRIGGER_INFO structure.

Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP:  This value is not supported.

SERVICE_CONFIG_LAUNCH_PROTECTED
12
The lpInfo parameter is a pointer a SERVICE_LAUNCH_PROTECTED_INFO structure.
Note  This value is supported starting with Windows 8.1.
 

[out, optional] lpBuffer

A pointer to the buffer that receives the service configuration information. The format of this data depends on the value of the dwInfoLevel parameter.

The maximum size of this array is 8K bytes. To determine the required size, specify NULL for this parameter and 0 for the cbBufSize parameter. The function fails and GetLastError returns ERROR_INSUFFICIENT_BUFFER. The pcbBytesNeeded parameter receives the needed size.

[in] cbBufSize

The size of the structure pointed to by the lpBuffer parameter, in bytes.

[out] pcbBytesNeeded

A pointer to a variable that receives the number of bytes required to store the configuration information, if the function fails with ERROR_INSUFFICIENT_BUFFER.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

The following error codes can be set by the service control manager. Others can be set by the registry functions that are called by the service control manager.

Return code Description
ERROR_ACCESS_DENIED
The handle does not have the SERVICE_QUERY_CONFIG access right.
ERROR_INSUFFICIENT_BUFFER
There is more service configuration information than would fit into the lpBuffer buffer. The number of bytes required to get all the information is returned in the pcbBytesNeeded parameter. Nothing is written to lpBuffer.
ERROR_INVALID_HANDLE
The specified handle is invalid.

Remarks

The QueryServiceConfig2 function returns the optional configuration information stored in the service control manager database for the specified service. You can change this configuration information by using the ChangeServiceConfig2 function.

You can change and query additional configuration information using the ChangeServiceConfig and QueryServiceConfig functions, respectively.

Examples

For an example, see Querying a Service's Configuration.

Note

The winsvc.h header defines QueryServiceConfig2 as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winsvc.h (include Windows.h)
Library Advapi32.lib
DLL Advapi32.dll

See also

ChangeServiceConfig

ChangeServiceConfig2

CreateService

OpenService

QueryServiceConfig

QueryServiceDynamicInformation

QueryServiceObjectSecurity

SERVICE_DELAYED_AUTO_START_INFO

SERVICE_DESCRIPTION

SERVICE_FAILURE_ACTIONS

SERVICE_FAILURE_ACTIONS_FLAG

SERVICE_PRESHUTDOWN_INFO

SERVICE_REQUIRED_PRIVILEGES_INFO

SERVICE_SID_INFO

Service Configuration

Service Functions