C++ – how to get process handle from process id

cwinapiwindows-vista

I have process Id , I want to get its process handle.

Is there any API available for that.

I tried to use OpenProcess but it returns NULL, and GetLastError =0.

This I am trying on Vista.

I guess I need to enable SeDebugPrivilege before using OpenProcess .
But for enabling SeDebugPrivilege I need to get its Process handle.

Best Answer

OpenProcess(PROCESS_ALL_ACCESS, TRUE, procId);

You'll need to verify that you're using a valid process ID, and that you're permitted the access rights you request from the process.