开发者

How to find process name with the help of process handle in c#

开发者 https://www.devze.com 2023-01-04 12:50 出处:网络
How to find process name with the help of process h开发者_开发技巧andle in c#....In an easy way, if you already got the handle, you can obtain all the processes

How to find process name with the help of process h开发者_开发技巧andle in c#....


In an easy way, if you already got the handle, you can obtain all the processes

Process.GetProcesses()

then compare your handle

IntPtr myHandle = ....    
foreach (Process process in processes)
                if (process.Handle = myHandle)
                    ....

and at last get the Name of the process

foreach (Process process in processes)
     if (process.Handle = myHandle)
     {
          string temp = process.ProcessName;
          ....
     }

You have the Process class defined inside the namespace

System.Diagnostics


Edit: Forgot that you need to call GetWindowThreadProcessId first to get the pid from the handle. More info here. And if you look the Pinvoke page here you can find a complete VB.Net sample.

Process.GetProcessById(id).ProcessName

In the System.Diagnostics namespace, see here for details.

0

精彩评论

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