Getting a list of current APPLICATIONS running, not processes c#

前端 未结 2 915
眼角桃花
眼角桃花 2021-01-20 20:40

I know you can get a list of the current processes that are running by using Process[] processes = Process.GetProcesses(); or Process[] processes = Proces

相关标签:
2条回答
  • 2021-01-20 21:36

    Get the list of processes, then filter by those processes that have a MainWindowHandle.

    A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window, the MainWindowHandle value is zero. The value is also zero for processes that have been hidden, that is, processes that are not visible in the taskbar. This can be the case for processes that appear as icons in the notification area, at the far right of the taskbar.

    If it has a main window, it's an "application" as far as the Task Manager is concerned.

    var processes = Process.GetProcesses()
        .Where(p=> p.MainWindowHandle != 0)
        .ToArray();
    
    0 讨论(0)
  • 2021-01-20 21:43

    Amy's answer is the one, but I had to change it to

    var running_apps = Process.GetProcesses()
                              .Where(p => (long)p.MainWindowHandle != 0)
                              .ToArray();
    
    0 讨论(0)
提交回复
热议问题