Pedro
Pedro

Reputation: 89

How can I get application by process

it's impossible to get app info(name, maybe other) by Process class? I know i can get .exe file name, but i want get app name. It is desirable that the solution be cross-platform?

Example: enter image description here

I can get MainWindowTitle 'Новая вкладка - Google Chrome', but i need application name like in task manager (Google Chrome). I can parse title, but this is not a universal way.

Upvotes: 0

Views: 270

Answers (1)

Klaus Gütter
Klaus Gütter

Reputation: 11997

To get the descrition of the executable file for a running process, you can use

string GetProcessDescription(Process process)
{
      try
      {
        return process.MainModule?.FileVersionInfo?.FileDescription;
      }
      catch
      {
        return null;
      }
}

The exception handler is necessary because you might not have the permission to access the information, or the process might not have a file module at all.

Upvotes: 1

Related Questions