Search code examples
pythonwindowsprocesscpupsutil

How to get a list of all running GUI apps?


I would like to know if it's possible to list all the GUI apps running on Windows with python.

I've been doing some research and people recommend using psutil, and it seems okay, however, it lists all the active processes, I haven't been able to find any resource on how to keep only the processes that are associated to an active GUI app (for example, Firefox, Chrome, Skype, Discord, and so on).

Is there any way to do this? Maybe not with Python (although that would be amazing), maybe through some C++? Getting the PID of the process would be enough.

EDIT: Thanks to chrisbyte and Vijaye Raji, win32gui and EnumWindows is exactly what I was looking for.


Solution

  • By GUI process I assume you mean processes that have a window attached. What you need is EnumWindows API which with a callback, and within the callback, you could use GetWindowThreadProcessId to get the process id of each window.

    Here's an answer that's close enough to get you going: https://stackoverflow.com/a/21767578