Querying a Service's Configuration
In the following example, a service configuration program uses the OpenService function to get a handle with SERVICE_QUERY_CONFIG access to an installed service object. Then the program uses the service object handle in the QueryServiceConfig function to retrieve the current configuration of the service.
VOID GetSampleServiceConfig()
{
LPQUERY_SERVICE_CONFIG lpqscBuf;
DWORD dwBytesNeeded;
// Open a handle to the service.
schService = OpenService(
schSCManager, // SCManager database
TEXT("Sample_Srv"), // name of service
SERVICE_QUERY_CONFIG); // need QUERY access
if (schService == NULL)
MyErrorExit("OpenService");
// Allocate a buffer for the information configuration.
lpqscBuf = (LPQUERY_SERVICE_CONFIG) LocalAlloc(
LPTR, 4096);
if (lpqscBuf == NULL)
MyErrorExit("LocalAlloc");
// Get and print the information configuration.
if (! QueryServiceConfig(
schService,
lpqscBuf,
4096,
&dwBytesNeeded) )
{
MyErrorExit("QueryServiceConfig");
}
printf("\nSample_Srv configuration: \n");
printf(" Type: 0x%x\n", lpqscBuf->dwServiceType);
printf(" Start Type: 0x%x\n", lpqscBuf->dwStartType);
printf(" Err Control: 0x%x\n", lpqscBuf->dwErrorControl);
printf(" Binary path: %s\n", lpqscBuf->lpBinaryPathName);
if (lpqscBuf->lpLoadOrderGroup != NULL)
printf(" Load order group: %s\n",
lpqscBuf->lpLoadOrderGroup);
if (lpqscBuf->dwTagId != 0)
printf(" Tag ID: %d\n", lpqscBuf->dwTagId);
if (lpqscBuf->lpDependencies != NULL)
printf(" Dependencies: %s\n", lpqscBuf->lpDependencies);
if (lpqscBuf->lpServiceStartName != NULL)
printf(" Start Name: %s\n",
lpqscBuf->lpServiceStartName);
LocalFree(lpqscBuf);
}