tags:

views:

194

answers:

4

I'd like to obtain the title of a program from the running processes name, using C#.

Example:

I know a program is called "msn.exe", and i want to obtain the title (name), "Windows Live Messenger" from the application. How would i go about doing that? Googling has left me at a loss.

+3  A: 

Hi. I think you need the Description field of WMI's Win32_Process Class:

http://msdn.microsoft.com/en-us/library/aa394599%28VS.85%29.aspx

It looks scary and foreign but it shouldn't be much code, just a few lines, when you're done.

Cheers!

uosɐſ
Excellent. Thanks!
Andreas Carlbom
+2  A: 

Check out FileVersionInfo class might be helpful for you.

      var info = Process.GetProcessesByName("devenv").FirstOrDefault();

        if (info != null)
        {
            Console.WriteLine(info.MainModule.FileVersionInfo.ProductName);
            Console.WriteLine(info.MainModule.FileVersionInfo.FileDescription);
        }
Stan R.
+1  A: 

Look at System.Diagnostics.Process.MainWindowTitle. It's not 100% consistent with the "Window Title" column in SysInternal's Process Explorer, but generally pulls the same thing.

Agent_9191
A: 

Stan R: Marking yours as the answer, ended up using the MainModule class in this way:

var info = Process.GetProcessesByName("processname").FirstOrDefault();
          if (info != null)
          {
              MessageBox.Show(info.MainWindowTitle);

}

Thanks for being patient with me :)

Andreas Carlbom