Reputation: 549
I have a Python code that needs to check if an executable is running or not, but in some different way. The executable takes some time to start (it shows a loading screen), depending on the speed of the computer itself.
When the executable is clicked, the process of starting it is shown as:
This takes a few seconds, depending on the computer speed.
According to the Task Manager, this is a background process:
When the executable is active (the loading screen is gone and the window is shown), the process is shifted from the background process to the Apps-section.
Now I have code that is able to find out if a certain process is running or not.
import psutil as psu
"gom_inspect.exe" in (p.name() for p in psu.process_iter())
But this code already states 'True' with the loading screen (as background process), while I need it to be 'True' if the program active and ready to use.
How can Python show 'True' when the executable is in the Apps-section instead of the background process-section?
Please let me know if something isn't clear.
I hope someone can help.
Upvotes: 1
Views: 1985
Reputation: 1726
You can use pywinauto get a list of open windows, without background processes. Then check if the title of the application you are looking for is in the list. Assuming the title is "GOM Inspect":
from pywinauto import Desktop
windows = Desktop(backend="uia").windows()
"GOM Inspect" in [w.window_text() for w in windows]
Upvotes: 2