.NET How to check if a Windows process is running as an “App” or as a “Background application”

后端 未结 3 1181
天涯浪人
天涯浪人 2020-12-20 00:43

On Windows 8.1 you go into the task manager and check the list of processes, there are two lists: - One for \"Apps\", which are visible foreground apps - One for \"Backgroun

相关标签:
3条回答
  • 2020-12-20 01:21

    Normally, if a process is an "App", it should have its own window's name, otherwise, it is a "Background application". Thus the code should be as follow:

    Process[] arrProcess = Process.GetProcesses();
    
    foreach (Process process in arrProcess)
    {
        if (!string.IsNullOrEmpty(process.MainWindowTitle))
        {
        //Do something with your App
        }
        else
        {
        //Do something with your Background process
        }
    }
    
    0 讨论(0)
  • 2020-12-20 01:39

    The property System.Diagnostics.Process.MainWindowHandle is zero when process has not UI (i.e. is background process).

    0 讨论(0)
  • 2020-12-20 01:43

    Services are also usually created by SYSTEM user - the column "User Name" in task manager.

    0 讨论(0)
提交回复
热议问题