Last active
December 16, 2015 13:09
-
-
Save Rurik/5440114 to your computer and use it in GitHub Desktop.
See if a process name is currently running or not (Windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on WMI code from http://mail.python.org/pipermail/python-win32/2006-March/004340.html | |
import os | |
def process_running(procname): | |
def find_pid(processname): | |
import win32com.client | |
for proc in win32com.client.GetObject('winmgmts:').InstancesOf('win32_process'): | |
if proc.Name.upper() == processname.upper(): | |
return proc.Properties_('ProcessId') | |
pid = find_pid(procname) | |
if not pid: | |
return False | |
try: | |
os.kill(int(pid), 0) | |
return False | |
except OSError, TypeError: | |
return True | |
print process_running("chrome.exe") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment