The Wayback Machine - https://web.archive.org/web/20240607170337/https://www.geeksforgeeks.org/how-to-check-if-an-application-is-open-in-python/
Open In App

How to check if an application is open in Python?

Last Updated : 24 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Using psutil

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.

Python3




# import module
import psutil
  
# check if chrome is open
"chrome.exe" in (i.name() for i in psutil.process_iter())


Output:

True

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.

Python3




# Import module
import wmi
  
# Initializing the wmi constructor
f = wmi.WMI()
  
flag = 0
  
# Iterating through all the running processes
for process in f.Win32_Process():
    if "chrome.exe" == process.Name:
        print("Application is Running")
        flag = 1
        break
  
if flag == 0:
    print("Application is not Running")


Output:

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.



Similar Reads

How to open multiple files using "with open" in Python?
Python has various highly useful methods for working with file-like objects, like the with feature. But what if we need to open several files in this manner? You wouldn't exactly be "clean" if you had a number of nested open statements. In this article, we will demonstrate how to open multiple files in Python using the with open statement. What is
2 min read
How to Open URL in Firefox Browser from Python Application?
In this article, we'll look at how to use a Python application to access a URL in the Firefox browser. To do so, we'll use the webbrowser Python module. We don't have to install it because it comes pre-installed. There are also a variety of browsers pre-defined in this module, and for this article, we'll be utilizing Firefox. The webbrowser module
2 min read
Build an Application to Search Installed Application using Python
In this article, we are going to write python scripts to search for an installed application on Windows and bind it with the GUI application. We are using winapps modules for managing installed applications on Windows. Prerequisite - Tkinter in Python To install the module, run this command in your terminal: pip install winapps Below is what the GU
6 min read
Python Pandas - Check if the interval is open on the left and right side
In pandas Interval.closed_left and Interval.closed_right attributes are used to check if the interval is open on left and right side. Intervals: Closed interval : closed ='both' represents closed interval. The closed interval contains its endpoints. it is of the form [a,b] and it has the condition a<=x<=b.Open interval: closed =' neither' rep
2 min read
Python PIL | Image.open() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. PIL.Image.open() Opens
2 min read
Python | sympy.sets.open() method
With the help of sympy.sets.open() method, we can make a set of values by setting interval values like right open or left open that means a set has right open bracket and left open brackets by using sympy.sets.open() method. Syntax : sympy.sets.open(val1, val2) Return : Return set of values with right and left open set. Example #1 : In this example
1 min read
Open a new Window with a button in Python-Tkinter
Python provides a variety of GUI (Graphic User Interface) such as PyQt, Tkinter, Kivy and soon. Among them, tkinter is the most commonly used GUI module in Python since it is simple and easy to learn and implement as well. The word Tkinter comes from the tk interface. The tkinter module is available in Python standard library.Note: For more informa
3 min read
How to open and close a file in Python
There might arise a situation where one needs to interact with external files with Python. Python provides inbuilt functions for creating, writing, and reading files. In this article, we will be discussing how to open an external file and close the same using Python. Opening a file in Python There are two types of files that can be handled in Pytho
4 min read
Python - Convert Tick-by-Tick data into OHLC (Open-High-Low-Close) Data
In this post, we'll explore a Python pandas package feature. We frequently find queries about converting tick-by-tick data to OHLC (Open, High, Low and Close). Using pandas kit this can be done with minimum effort. The OHLC data is used over a unit of time (1 day, 1 hour etc.) to perform a technical analysis of price movement. The First Step: The f
2 min read
Open computer drives like C, D or E using Python
Have you ever wondered that you can open your drives by just typing C, D or E and then that drives are open.This can be possible by using Python. So, for performing this task this we are using os.startfile() method of OS library. This Method start a file with its associated program. Syntax: os.startfile(file_name) Return: None. Now let's see the co
1 min read
Article Tags :
Practice Tags :