How to find process name with the help of process handle in c#
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.
精彩评论