How to get an application's process name?

2020-08-26 10:58发布

问题:

I am trying to develop a sample application that finds the process name of a particular application.. Suppose there is an application by name XYZ.exe.. But when the XYZ.exe application is executed, it is not necessary that it holds the same process name.. Let the application run under the process name abc.exe..

Now my question is this.. Is it possible to find the process name of XYZ.exe?

Any help would much appreciated...

Thanks, Ram

回答1:

It's simple:

foreach (Process pr in Process.GetProcesses())
{
     try
     {
         Console.WriteLine("App Name: {0}, Process Name: {1}", Path.GetFileName(pr.MainModule.FileName), pr.ProcessName);
     }
     catch { }
}


标签: c#