[英]Get program title from process name in C#
I'd like to obtain the title of a program from the running processes name, using C#. 我想使用C#从正在运行的进程名称中获取程序的标题。
Example: 例:
I know a program is called "msn.exe", and i want to obtain the title (name), "Windows Live Messenger" from the application. 我知道一个程序叫做“ msn.exe”,我想从应用程序中获取标题(名称)“ Windows Live Messenger”。 How would i go about doing that?
我将如何去做? Googling has left me at a loss.
谷歌搜索使我茫然。
I think you need the Description field of WMI's Win32_Process Class: 我认为您需要WMI的Win32_Process类的Description字段:
http://msdn.microsoft.com/en-us/library/aa394599%28VS.85%29.aspx http://msdn.microsoft.com/zh-CN/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! 干杯!
Check out FileVersionInfo class might be helpful for you. 查看FileVersionInfo类可能对您有所帮助。
var info = Process.GetProcessesByName("devenv").FirstOrDefault();
if (info != null)
{
Console.WriteLine(info.MainModule.FileVersionInfo.ProductName);
Console.WriteLine(info.MainModule.FileVersionInfo.FileDescription);
}
Look at System.Diagnostics.Process.MainWindowTitle
. 查看
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. 它与SysInternal的Process Explorer中的“ Window Title”(窗口标题)列并非100%一致,但通常会产生相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.