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
2010-01-18 06:08:05
The wmi module will make this even easier. http://timgolden.me.uk/python/wmi/index.html It is a lightweight wrapper around win32com
codeape
2010-01-18 10:39:14