4

I am trying to get a list of all processes which are of the type "app" (as opposed to "Background Process" or "Windows Process").

"App" type

Unfortunately, although I know that...

var processList = Process.GetProcesses();

will get me a list of all processes running on the system, I am at a loss for how to get the 'type' of the process. 'Process' does have a method 'GetType', but it doesn't seem to refer to the "type" that I'm referring to, and that TaskManager refers to in the above image.

Does anyone know how I can get this value that Task Manager refers to as "type" into a variable for a given process?

Note: C#.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
user2328093
  • 99
  • 3
  • 9
  • 1
    I don't know for sure the logic Windows 8 Task Manager uses to categorize processes. You'd probably have to ask Raymond Chen. :) But I suspect that it's looking at whether the process has at least one UI window. You won't get that from the `Process` class, but you can correlate information about windows that are present and the processes that own them. – Peter Duniho Nov 23 '14 at 08:20
  • 1
    Maybe that type bears on the process' `MainWindowHandle` property; not sure of proper using of the `Refresh` [method](http://stackoverflow.com/a/16185802/3439404). In any case: a process has a main window associated with it only if the process has a graphical interface, otherwise the `MainWindowHandle` value is zero. – JosefZ Nov 23 '14 at 20:15

2 Answers2

6

I couldn't find the exact answer, but I found what helps me. You need to use the MainWindowHandle property of class Process.

var processes = Process.GetProcesses().Where(pr => pr.MainWindowHandle != IntPtr.Zero);

foreach (Process proc in processes)
    Console.WriteLine(proc.ProcessName);

Warning

If you try to get proc.MainModule.FileName you may see the Win32Exception exception. To avoid this issue I compile my project as x64 (your project -> properties -> Build -> Platform target -> x64).

Razor23 Donetsk
  • 466
  • 1
  • 5
  • 13
0

Meet the same question, and find an answer in the follow link:https://devblogs.microsoft.com/oldnewthing/20171219-00/?p=97606

  • If the process has a visible window, then Task Manager calls it an “App”.
  • If the process is marked as critical, then Task Manager calls it a “Windows Process”.
  • Otherwise, Task Manager calls it a “Background Process”.
Dharman
  • 30,962
  • 25
  • 85
  • 135
12tall
  • 101
  • 7