UdoScheuvens
Programmer
I have a problem with a function that works good under Windows 95/98. The documentation says that it also should work under Windows 2000, but when I try I get errors. First of all the code:
Now the results:
Under Windows 95 this code works fine. All processes give the message "Worked...". The ID is 6 or 7 digit negative number.
Under Windows 2000 the first call also works fine. But within the "while"-loop all calls fail (message "Failed...)
The error code returned by GetLastError is 5 (ERROR_ACCESS_DENIED). The ID is a 3 digit positive number.
What has to be done to make this code work under Windows 2000?
Udo
Code:
long lErr;
HANDLE lSnapshot1, lSnapshot2;
char sBuffer[200];
PROCESSENTRY32 ulpPE32;
BOOL bResult;
lSnapshot1 = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ulpPE32.dwSize = sizeof(ulpPE32);
bResult = Process32First(lSnapshot1, &ulpPE32);
lErr = GetLastError();
if (lErr == ERROR_NO_MORE_FILES)
{
MessageBox (NULL, "No processes!", NULL, MB_OK);
return;
}
while (bResult == TRUE)
{
lSnapshot2 = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ulpPE32.th32ProcessID);
if (lSnapshot2 == (HANDLE)-1)
{
lErr = GetLastError();
wsprintf (sBuffer, "Failed for >%s< %ld: %ld", ulpPE32.szExeFile, ulpPE32.th32ProcessID, lErr);
MessageBox (NULL, sBuffer, NULL, MB_OK);
}
else
{
wsprintf (sBuffer, "Worked for >%s< %ld", ulpPE32.szExeFile, ulpPE32.th32ProcessID);
MessageBox (NULL, sBuffer, NULL, MB_OK);
CloseHandle(lSnapshot2);
}
bResult = Process32Next(lSnapshot1, &ulpPE32);
lErr = GetLastError();
if (lErr == ERROR_NO_MORE_FILES)
{
MessageBox (NULL, "That's it!", NULL, MB_OK);
bResult = FALSE;
}
}
Now the results:
Under Windows 95 this code works fine. All processes give the message "Worked...". The ID is 6 or 7 digit negative number.
Under Windows 2000 the first call also works fine. But within the "while"-loop all calls fail (message "Failed...)
The error code returned by GetLastError is 5 (ERROR_ACCESS_DENIED). The ID is a 3 digit positive number.
What has to be done to make this code work under Windows 2000?
Udo