我想获取它在Windows上运行的当前应用程序的名称。
例如,如果我使用,即此功能提供“Internet Explorer”或者如果我使用Google Chrome,请提供Chrome ...
答案 0 :(得分:8)
System.AppDomain.CurrentDomain.FriendlyName
或者
System.Reflection.Assembly.GetExecutingAssembly()
或者如果您想要活动窗口的名称,那么您应该看一下;
How do I get the title of the current active window using c#?
答案 1 :(得分:0)
答案 2 :(得分:0)
试试这个,如果您使用过GetWindowThreadProcessId。
public String GetActiveFileNameTitle()
{
IntPtr hWnd = GetForegroundWindow();
uint procId = 0;
GetWindowThreadProcessId(hWnd, out procId);
var proc = Process.GetProcessById((int)procId);
if (proc != null)
{
return proc.MainModule.FileVersionInfo.ProductName;
}
}