Skip to main content
QueryServiceConfig2 function

Retrieves the optional configuration parameters of the specified service.

Syntax


BOOL WINAPI QueryServiceConfig2(
  _In_       SC_HANDLE hService,
  _In_       DWORD dwInfoLevel,
  _Out_opt_  LPBYTE lpBuffer,
  _In_       DWORD cbBufSize,
  _Out_      LPDWORD pcbBytesNeeded
);

Parameters

hService [in]

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.

dwInfoLevel [in]

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

ValueMeaning
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.

 

lpBuffer [out, optional]

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.

cbBufSize [in]

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

pcbBytesNeeded [out]

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 codeDescription
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.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Winsvc.h (include Windows.h)

Library

Advapi32.lib

DLL

Advapi32.dll

Unicode and ANSI names

QueryServiceConfig2W (Unicode) and QueryServiceConfig2A (ANSI)

See also

ChangeServiceConfig
ChangeServiceConfig2
CreateService
OpenService
QueryServiceConfig
QueryServiceDynamicInformation
QueryServiceObjectSecurity
Service Configuration
Service Functions
SERVICE_DELAYED_AUTO_START_INFO
SERVICE_DESCRIPTION
SERVICE_FAILURE_ACTIONS
SERVICE_FAILURE_ACTIONS_FLAG
SERVICE_PRESHUTDOWN_INFO
SERVICE_REQUIRED_PRIVILEGES_INFO
SERVICE_SID_INFO