Alternative GetProcessID for Windows 2000

I accidentally removed Win2K compatibility using GetProcessID .

I use it so that I get the basic HWND for the running 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 on how the same function can be obtained on Win2K?

+3
source share
4 answers

There is a “sorting unsupported” function: ZwQueryInformationProcess (): see

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

( ), . Windows, , , GetProcAddress() GetProcessId() XP , ZwQueryInformationProcess() Win2K.

+6

. . ZwQueryInformationProcess:

[ZwQueryInformationProcess Windows. .]

, Microsoft , . DavidK ZwQueryInformationProcess , GetProcessID, GetProcessID , (XP SP1 ).

+5

DavidK - . ​​ .

, . , , .

Win2K Vista:

#include "Winternl.h"

typedef DWORD (WINAPI* pfnGetProcID)(HANDLE h);

typedef NTSTATUS (WINAPI* pfnQueryInformationProcess)(
    HANDLE ProcessHandle,
    PROCESSINFOCLASS ProcessInformationClass,
    PVOID ProcessInformation,
    ULONG ProcessInformationLength,
    PULONG ReturnLength);

DWORD MyGetProcessId(HANDLE h)
{
    static pfnQueryInformationProcess ntQIP = (pfnQueryInformationProcess) GetProcAddress(GetModuleHandle("NTDLL.DLL"),"NtQueryInformationProcess");
    static pfnGetProcID getPId  = (pfnGetProcID) GetProcAddress(GetModuleHandle("KERNEL32.DLL"),"GetProcessId");

    if ((ntQIP == NULL) && (getPId == NULL))
        throw Exception("Can't retrieve process ID : GetProcessID not supported");

    if (getPId != NULL)
        return getPId(h);
    else
    {
        PROCESS_BASIC_INFORMATION info;
        ULONG returnSize;
        ntQIP(h, ProcessBasicInformation, &info, sizeof(info), &returnSize);  // Get basic information.
        return info.UniqueProcessId;
    }
}
+2

, ZwQueryInformationProcess() NtQIP, , , NT 3.5,

-1

Source: https://habr.com/ru/post/1699275/


All Articles