- 1 year ago
How to get the application name having the process name using python?
Comment
1 / 1
In Python, you can use the psutil
library to retrieve information about running processes on your system, including the application name associated with a specific process name. Here's an example of how you can get the application name using the process name:
pythonimport psutil
def get_application_name(process_name):
for process in psutil.process_iter(['name', 'exe']):
if process.info['name'] == process_name:
return process.info['exe']
return None
# Example usage
process_name = 'chrome.exe' # Replace with the process name you want to search for
application_name = get_application_name(process_name)
if application_name:
print(f"Application name: {application_name}")
else:
print("Process not found.")
This code uses psutil.process_iter()
to iterate over all running processes and retrieve the process name and executable path (exe
). It then compares the process name with the one you're looking for. If a match is found, it returns the associated application name. If no match is found, it returns None
.
Note that the process name may not always match the application name exactly, as some applications may have different process names.