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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With