views:

172

answers:

2

Good Day,

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.

TIA,

coson

A: 

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();
        }
    }
}
JP Alioto
A: 

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 querry the AssemblyDescriptionAttribute custom attribute.

CsTamas