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

C# 如何在C中获取当前应用程序的名称#,c#,process,C#,Process,我想获取在windows上运行的当前应用程序的名称 例如,如果我使用,即,此函数给出“Internet explorer”,或者如果我使用Google chrome,则给出chrome… System.AppDomain.CurrentDomain.FriendlyName 或许 System.Reflection.Assembly.GetExecutingAssembly() 或者,如果您的意思是想要活动窗口的名称,那么您应该查看 您可以使用 请再看看这个问题: 如果使用了GetWindo

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

例如,如果我使用,即,此函数给出“Internet explorer”,或者如果我使用Google chrome,则给出chrome…

System.AppDomain.CurrentDomain.FriendlyName
或许

System.Reflection.Assembly.GetExecutingAssembly()
或者,如果您的意思是想要活动窗口的名称,那么您应该查看

您可以使用

请再看看这个问题:


如果使用了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;
        }

    }

您的意思是想要当前活动窗口的名称吗?如有,请参阅
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;
        }

    }