get process handle by PID

后端 未结 1 1162
慢半拍i
慢半拍i 2021-01-28 05:20

I want to get the 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 funct

相关标签:
1条回答
  • 2021-01-28 05:43

    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 讨论(0)
提交回复
热议问题