I need to get the Task Manager process description

2

I need to get the name of the process that is active on the screen, however I need to bring the same one appears in the Task Manager in description.

For example if I use processName it will bring "Chrome" I need it to be description = Google Chrome.

I've tried this:

 foreach (Process p in Process.GetProcesses())
                {


                    if (p.MainWindowTitle.Length > 0)
                    {


                        if (app.NomeAplicativo.Contains(p.ProcessName))
                        {
                            Console.WriteLine("Process Name:" + p.ProcessName.ToString());
                        }

                        Console.WriteLine("Process Name:" + p.ProcessName);
                    }
                }

And using this face:

  public static Int32 GetWindowProcessID(IntPtr hwnd)
        {
            // Esta função é usada para obter o AID do processo ativo ...
            Int32 pid;
            GetWindowThreadProcessId(hwnd, out pid);
            return pid;
        }

But in both, I can not get the description of the process.

    
asked by anonymous 23.05.2016 / 15:56

2 answers

1

As this response in SO has a form that resolves in most situations, but not guaranteed. You need to use Windows API functions that are not normally available in .Net:

[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint ProcessId);

[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();

string GetActiveProcessFileName() {
    IntPtr hwnd = GetForegroundWindow();
    uint pid;
    GetWindowThreadProcessId(hwnd, out pid);
    Process p = Process.GetProcessById((int)pid);
    p.MainModule.FileName.Dump();
}
    
23.05.2016 / 16:03
0

Uses the MainWindowTitle property of the Process class

    
24.05.2016 / 00:49