如何在 C# 中获取当前在窗口上运行的应用程序?
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;
}
}