开发者

get process handle by PID

开发者 https://www.devze.com 2023-01-05 11:20 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消