I need to get a description of the task manager process

Asked

Viewed 247 times

3

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

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

I’ve tried it like 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 guy:

  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’t get the description of the process.

  • Lucas, download the source of Processhacker, there you find the way to do this search. But you will need to use the call of Interop.

  • Did any of the answers solve your problem? Do you think you can accept one of them? If you haven’t already, see [tour] how to do this. You would help the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site.

2 answers

1

According to this response in the OS has a form that solves in most situations, but not guaranteed. You need to use Windows API functions that are not normally available on . 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();
}

I put in the Github for future reference.

  • I already tried to do this, but when using Mainmodule also not sure. Ai gives the following error (It is not possible to enumerate the modules of the process. ) And sometimes depending on what this open works, but for some open applications it gives this other error. (Only a portion of a Readprocessmemory or Writeprocessmemory order has been completed)

  • There doesn’t seem to be a better solution.

0

Use the property Mainwindowtitle class Process

  • Worked out using the Mainwindowtitle property. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.