2017-03-08 31 views
0

这里是如何获得Windows的运行的应用程序不是所有的过程

Process[] process = Process.GetProcesses(); 

Console.WriteLine("System Running Process \n\n"); 

foreach (Process Proc in process) 
{ 
    if (!string.IsNullOrEmpty(Proc.MainWindowTitle)) 
    { 
     IntPtr wHnd = Proc.MainWindowHandle; 

     Console.WriteLine("Process Name {0} : status {1}", Proc.ProcessName, !IsIconic(wHnd)); 
     //ShowWindowAsync(wHnd, SW_RESTORE); 


     //SetForegroundWindow(wHnd); 
     Console.WriteLine("--------------------"); 
     // Console.WriteLine(Proc.ProcessName); 
    } 
} 

代码红色标记的应用程序的输出也不会使用,但在研究背景进程中运行,并显示

enter image description here

代码

这实际上是我想要的输出

enter image description here

+0

检查[this](http://stackoverflow.com/questions/35813376/how-do-i-check-if-a-running-process-is-a-background-process)。 – Berkay

回答

0

可以使用的Proc.MainModule.FileVersionInfo.ProductName代替Proc.ProcessName

Console.WriteLine("Process Name {0} : status {1}", 
        Proc.MainModule.FileVersionInfo.ProductName, 
        !IsIconic(wHnd)); 

编辑:顺便说一句,如果你需要的标题,你也可以使用Proc.MainWindowTitle

+0

无法保证文件版本信息中的内容与Windows标题栏或任务管理器中显示的内容相匹配 – MickyD

+0

MickyD您是否看到过我使用线程附加的屏幕截图?下面的代码?在此先感谢我想要的输出和您的代码行是给不同的名称相同的结果 –

0

如果你想找到只显示有窗户的过程,您应该检查Process.MainWindowHandle以确保它不是IntPtr.Zero

foreach (Process Proc in process.Where(p => p.MainWindowHandle != IntPtr.Zero)) 
{ 
    ... 
相关问题