int main(int argc, char *argv[])
{
#define SZ_ENUM_BUF 4096
ENUM_SERVICE_STATUS_PROCESS essServiceStatus
SZ_ENUM_BUF];
DWORD dwBufSize =
sizeof(essServiceStatus);
DWORD dwBytesNeeded =
0;
DWORD dwServicesReturned =
0;
DWORD dwResumeHandle =
0;
DWORD dwIndex =
0;
SC_HANDLE hSCManager =
NULL;
hSCManager= OpenSCManager(NULL,
NULL,SC_MANAGER_ALL_ACCESS);
if (hSCManager == NULL)
{
// failure
printf("OpenSCManager error code %d\n",GetLastError
());
printf("Program completion\n");
return 0;
}
if (!EnumServicesStatusEx(hSCManager,
SC_ENUM_PROCESS_INFO,
SERVICE_WIN32,
SERVICE_STATE_ALL,
(LPBYTE)essServiceStatus,
dwBufSize,
&dwBytesNeeded,
&dwServicesReturned,
&dwResumeHandle,
NULL))
{
// failure
printf("EnumServicesStatusEx error code %
d\n",GetLastError());
}
printf("Program completion\n");
CloseHandle(hSCManager);
return 0;
}
The code was changed to call EnumServicesStatus() twice,
first to get the length of the buffer that gets allocated
and used in the second call. The first call gets an
ERROR_MORE_DATA error code with pcbBytesNeeded being the
returned needed buffer size.
To the sender of this - thank you.
>.
>