SunilRai86
SunilRai86

Reputation: 1020

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

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

Upvotes: 0

Views: 1421

Answers (2)

Marcello Faga
Marcello Faga

Reputation: 1204

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

Upvotes: 2

Hans Olsson
Hans Olsson

Reputation: 55059

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.

Upvotes: 0

Related Questions