QueryServiceConfig2
The QueryServiceConfig2 function retrieves the optional configuration parameters of the specified service.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684935(v=vs.85).aspx
<pre style="padding: 5px; margin-top: 0px; margin-bottom: 0px; overflow: auto; word-wrap: normal; font-family: Consolas, Courier, monospace !important; font-size: 14px; line-height: 20px; ">BOOL WINAPI <strong>QueryServiceConfig2</strong>( _In_ SC_HANDLE <strong>hService</strong>, _In_ DWORD <strong>dwInfoLevel</strong>, _Out_opt_ LPBYTE <strong>lpBuffer</strong>, _In_ DWORD <strong>cbBufSize</strong>, _Out_ LPDWORD <strong>pcbBytesNeeded</strong> );
Parameters
-
hService
- [in] 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] Configuration information to be queried. This parameter can be one of the following values.
Value Meaning SERVICE_CONFIG_DESCRIPTION
1The lpBuffer parameter is a pointer to aSERVICE_DESCRIPTION structure. SERVICE_CONFIG_FAILURE_ACTIONS
2The lpBuffer parameter is a pointer to aSERVICE_FAILURE_ACTIONS structure.
lpBuffer
-
[out] 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 will fail and GetLastError will return ERROR_INSUFFICIENT_BUFFER. The pcbBytesNeeded parameter will receive the required size.
cbBufSize
- [in] Size of the structure pointed to by the lpBuffer parameter, in bytes. pcbBytesNeeded
- [out] Pointer to a variable that receives the number of bytes needed to store the configuration information, if the function fails with ERROR_INSUFFICIENT_BUFFER.
Return Values
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 thelpBuffer 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 theChangeServiceConfig2 function.
You can change and query additional configuration information using the ChangeServiceConfig andQueryServiceConfig functions, respectively.
Example Code
For an example, see Querying a Service's Configuration.
Requirements
Client | Requires Windows XP or Windows 2000 Professional. |
---|---|
Server | Requires Windows Server 2003 or Windows 2000 Server. |
Header | Declared in Winsvc.h; include Windows.h. |
Library | Link to Advapi32.lib. |
DLL | Requires Advapi32.dll. |
Unicode | Implemented as QueryServiceConfig2W (Unicode) and QueryServiceConfig2A (ANSI). |