在此处找到解决方案:http://blogs.msdn.com/b/oldnewthing/archive/2007/10/08/5351207.aspx
我正在尝试列出正在运行的应用程序,我在几个论坛上找到了这个解决方案:
Process[] processes = Process.GetProcesses();
foreach (var proc in processes)
{
if (!string.IsNullOrEmpty(proc.MainWindowTitle))
Console.WriteLine(proc.MainWindowTitle);
}
exept这不会给我与按alt-tab时相同的列表。例如:firefox,explorer和iexplore都返回一个空的/ null MainWindowTitle。有没有其他方法可以访问此列表?也许通过windowsAPI?
我正在使用Windows 7 32位
先谢谢你。
答案 0 :(得分:0)
答案 1 :(得分:0)
试试这个(取自here),但我不确定它是否解决了您的问题:
static void Main(string[] args)
{
GetProcesses();
GetApplications();
Console.Read();
}
public static void GetProcesses()
{
StringBuilder sb = new StringBuilder();
ManagementClass MgmtClass = new ManagementClass("Win32_Process");
foreach (ManagementObject mo in MgmtClass.GetInstances())
Console.WriteLine("Name:" + mo["Name"] + "ID:" + mo["ProcessId"]);
Console.WriteLine();
}
public static void GetApplications()
{
StringBuilder sb = new StringBuilder();
foreach (Process p in Process.GetProcesses("."))
try
{
if (p.MainWindowTitle.Length > 0)
{
Console.WriteLine("Window Title:" + p.MainWindowTitle.ToString());
Console.WriteLine("Process Name:" + p.ProcessName.ToString());
Console.WriteLine("Window Handle:" + p.MainWindowHandle.ToString());
Console.WriteLine("Memory Allocation:" + p.PrivateMemorySize64.ToString());
}
}
catch { }
}