Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get process handle from process id?

Tags:

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.

like image 268
anand Avatar asked Feb 08 '10 11:02

anand


People also ask

How do you find the process handle?

If you have a process identifier, you can get the process handle by calling the OpenProcess function. OpenProcess enables you to specify the handle's access rights and whether it can be inherited. A process can use the GetCurrentProcess function to retrieve a pseudo handle to its own process object.

How do you get a PID out of a window handle?

You can use the following Windows API: [DllImport("user32. dll", SetLastError=true)] static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId); You pass in the HWND and use the out parameter to return the PID.

How do I find the PID of a process in Windows?

Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column. Click on any column name to sort.

What is a Windows process handle?

A process handle is an integer value that identifies a process to Windows. The Win32 API calls them a HANDLE; handles to windows are called HWND and handles to modules HMODULE. Threads inside processes have a thread handle, and files and other resources (such as registry keys) have handles also.


1 Answers

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.

like image 177
Matt Joiner Avatar answered Oct 13 '22 11:10

Matt Joiner