4

我想获取它在 Windows 上运行的当前应用程序的名称。

例如,如果我使用 ie,此功能将提供“Internet Explorer”,或者如果我使用 Google chrome,则提供 Chrome ...

4

3 回答 3

9
System.AppDomain.CurrentDomain.FriendlyName

或者可能

System.Reflection.Assembly.GetExecutingAssembly()

或者如果您的意思是您想要活动窗口的名称,那么您应该查看;

如何使用 c# 获取当前活动窗口的标题?

于 2013-04-17T02:10:47.610 回答
1

您可以使用Assembly.FullName

System.Reflection.Assembly.GetEntryAssembly().FullName;

也请看看这个问题:

如何在 C# 中获取当前可执行文件的名称?

于 2013-04-17T02:24:50.723 回答
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;
        }

    }
于 2013-06-28T07:15:43.447 回答