views:

83

answers:

2

I need a script that check if a particular process is running and return something if not found. I know that this can be done using subprocess, but is there a simpler way to do it?

+2  A: 

On Windows, you can use WMI:

import win32com.client

def find_process(name):
    objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
    objSWbemServices = objWMIService.ConnectServer(".", "root\cimv2")
    colItems = objSWbemServices.ExecQuery("Select * from Win32_Process")
    for objItem in colItems: 
        if name == objItem.Caption:
            return 1
    return 0

print find_process("SciTE.exe")
luc
The wmi module will make this even easier. http://timgolden.me.uk/python/wmi/index.html It is a lightweight wrapper around win32com
codeape
A: 

Take a look at: getting process information on windows

Michał Niklas