Reputation: 8659
I am trying to retrieve process information and I'm aware that I can use:
Process[] myProcesses = Process.GetProcesses();
but how do I retrieve the process description? Is it via some Win32 API call? I'm running Vista and when I click under the Processes tab in Task Manager, I see the description.
Upvotes: 11
Views: 9887
Reputation: 4153
What you see in Task Manager is actually the Description field of the executable image.
You can use the GetFileVersionInfo()
and VerQueryValue()
WinAPI calls to access various version informations, e.g. CompanyName or FileDescription.
For .Net way, use the FileDescription
member of FileVersionInfo
, instantiated with the executable name got via Process.MainModule.FileName
.
Another way would be through Assembly
. Load the Assembly from the executable image, then query the AssemblyDescriptionAttribute
custom attribute.
Upvotes: 13
Reputation: 858
You just have to go a bit further down the properties. Suppose you have an instance of notepad running.
Process[] proc = Process.GetProcessesByName("notepad");
Console.WriteLine("Process version- " + proc[0].MainModule.FileVersionInfo.FileVersion);
Console.WriteLine("Process description- " + proc[0].MainModule.FileVersionInfo.FileDescription);
There you go !
Upvotes: 12
Reputation: 45117
This is the only way I could see to do it. I tried Process and Win32_Process, but no go.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Diagnostics;
namespace Management
{
class Program
{
static void Main(string[] args)
{
var ps = Process.GetProcesses();
foreach (var p in ps)
{
try
{
var desc = FileVersionInfo.GetVersionInfo(p.MainModule.FileName);
Console.WriteLine(desc.FileDescription);
}
catch
{
Console.WriteLine("Access Denied");
}
}
Console.ReadLine();
}
}
}
Upvotes: 1