Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to GetProcessID for Windows 2000

I've accidentally removed Win2K compatibility from an application by using GetProcessID.

I use it like this, to get the main HWND for the launched application.

ShellExecuteEx(&info); // Launch application
HANDLE han = info.hProcess; // Get process

cbinfo.han = han;

//Call EnumWindows to enumerate windows....
//with this as the callback

static BOOL CALLBACK enumproc(HWND hwnd, LPARAM lParam)
{
  DWORD id;
  GetWIndowThreadProcessID(hwnd, &id);
  if (id == GetProcessID(cbinfo.han))
    setResult(hwnd)
 ...
}

Any ideas how the same function could be acheived on Win2K?

like image 274
Roddy Avatar asked Dec 14 '22 06:12

Roddy


1 Answers

There is an 'sort-of-unsupported' function: ZwQueryInformationProcess(): see

http://msdn.microsoft.com/en-us/library/ms687420.aspx

This will give you the process id (amongst other things), given the handle. This isn't guaranteed to work with future Windows versions, so I'd suggest having a helper function that tests the OS version and then uses GetProcAddress() to call either GetProcessId() for XP and above, and ZwQueryInformationProcess() for Win2K only.

like image 194
DavidK Avatar answered Dec 15 '22 19:12

DavidK