How to check if an application is open in Python?
This article is about How to check if an application is open in a system using Python. You can also refer to the article Python – Get list of running processes for further information.
In the below approaches, we will be checking if chrome.exe is open in our system or not.
The psutil is a system monitoring and system utilization module of python. It is useful mainly for system monitoring, profiling and limiting process resources, and management of running processes. Usage of resources like CPU, memory, disks, network, sensors can be monitored. It is supported in Python versions 2.6, 2.7, and 3.4+. You can install psutil module by using the following command
pip install psutil
We will use the psutil.process_iter() method, it returns an iterator yielding a process class instance for all running processes on the local machine.
We import the psutil module. Then we search for chrome.exe in all running processes on the local machine using psutil.process_iter(). If found it will return output as TRUE, else FALSE.
Using WMI (only Windows User)
The wmi module can be used to gain system information of a Windows machine and can be installed using the below command:
pip install wmi
Its working is similar to psutil. Here, we check if a particular process name is present in the list of running processes.
Application is Running
We import the wmi module. Then we search for chrome.exe in all running processes on the local machine by iterating through the process names. If it matches with the process. Name, it will print Application is Running, else Application is not Running.