Skip to content

Instantly share code, notes, and snippets.

@Rurik
Last active December 16, 2015 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rurik/5440114 to your computer and use it in GitHub Desktop.
Save Rurik/5440114 to your computer and use it in GitHub Desktop.
See if a process name is currently running or not (Windows)
# 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