get process handle by PID
I want to get th开发者_如何学JAVAe handle of a process by the process name.
I have PID but when I use openProcess
to get the handle always it will return 0 or 180, the function that I use to get the PID working properly
Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,False,PID);
What should I do?
There is no direct way to get a process handle when all you know is its name, unless you're using CreateProcess
.
Instead, you can use CreateToolhelp32Snapshot
, Process32First
, and Process32Next
to search for all processes having the name you want. Keep in mind that there may be multiple processes with the same name. Those functions will tell you the process ID. Once you have that, you can use OpenProcess
, as you've already demonstrated. If OpenProcess
returns something other than zero (such as 180), then it has given you a valid process handle.
精彩评论