如何在C#中获取当前应用程序的名称

时间:2013-04-17 02:08:24

标签: c# process

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

例如,如果我使用,即此功能提供“Internet Explorer”或者如果我使用Google Chrome,请提供Chrome ...

3 个答案:

答案 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)

您可以使用Assembly.FullName

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

还请看一下这个问题:

How do I get the name of the current executable in C#?

答案 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;
        }

    }