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 th开发者_如何学编程at? Googling has left me at a loss.
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);
}
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!
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.
精彩评论