How do I get a list of "project names" from processes (not process name or window title)

362 Views Asked by At

I'm looking for a way to list every process' application name. The ones like project names when you make a project in visual studio.

What I'm not looking for:

  1. Window title
Process[] processes = Process.GetProcesses();
foreach (Process p in processes)
{
    if (!String.IsNullOrEmpty(p.MainWindowTitle))
    {
        Console.WriteLine(p.MainWindowTitle);
    }
}
  1. Process name
Process[] processes = Process.GetProcesses();
foreach (Process p in processes)
{
    Console.WriteLine(p.ProcessName);
}

What I am looking for:

Entries in a task manager list:

Task Manager List

1

There are 1 best solutions below

2
On

While the p.MainModule throws for some processes (looking into it),

What you need can be achieved like this:

    Process p = Process.GetProcessesByName("winword")[0];
    string fileName = p.MainModule.FileName;

    FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(fileName);

    // Writes "Microsoft Word"
    Console.Write(myFileVersionInfo.FileDescription);

EDIT 1:

It seems like the p.MainModule is not accessible if you run as 32 bit on a 64 bit environment.

When compiled to x64, all the process running with my user on my system could be displayed. For the others, elevation is probably required.

Failed: svchost, Reason: Access is denied
Succeeded: chrome = Google Chrome
Failed: sqlservr, Reason: Access is denied
Succeeded: SCNotification = SCNotification
Succeeded: VirtualMIDISynth = CoolSoft VirtualMIDISynth
Failed: NisSrv, Reason: Access is denied
Failed: TabTip32, Reason: Access is denied
Failed: RegSrvc, Reason: Access is denied
Failed: dwm, Reason: Access is denied
Failed: LMS, Reason: Access is denied
Failed: svchost, Reason: Access is denied
Succeeded: chrome = Google Chrome
Failed: EvtEng, Reason: Access is denied
Succeeded: OmniSharp = OmniSharp
Failed: taskhost, Reason: Access is denied
Failed: svchost, Reason: Access is denied
Succeeded: Code = Visual Studio Code
Succeeded: devenv = Microsoft Visual Studio 2013
Succeeded: ChsIME = Microsoft IME
Failed: SppExtComObj, Reason: Access is denied
Failed: svchost, Reason: Access is denied
Failed: WmiPrvSE, Reason: Access is denied
Succeeded: Code = Visual Studio Code
Failed: isa, Reason: Access is denied
Succeeded: conhost = Console Window Host