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

问题描述 投票:0回答:3

如何在 C# 中获取当前在窗口上运行的应用程序?

c# process
3个回答
9
投票
System.AppDomain.CurrentDomain.FriendlyName

或者也许

System.Reflection.Assembly.GetExecutingAssembly()

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

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


1
投票

您可以使用Assembly.FullName

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

也请看看这个问题:

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


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

    }
© www.soinside.com 2019 - 2024. All rights reserved.