简体   繁体   中英

How to get process “type” (App, Background Process, or Windows Process)

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

“应用”类型

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#.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM