how to get process handle from process id?

anand picture anand · Feb 8, 2010 · Viewed 53.3k times · Source

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.

Answer

Matt Joiner picture Matt Joiner · Feb 8, 2010
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.