views:

863

answers:

5

I have one function in python which should start running when some process (eg. proc.exe) showed up in tasks manager.
How can I monitor processes running in tasks manager with python?

A: 

I`m using Windows Vista SP1

+6  A: 

here is something, I've adapted from microsoft

import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_Process")
for objItem in colItems:
   print "Name: ", objItem.Name
   print "File location: ", objItem.ExecutablePath

There is here a lot of nice examples for python and windows

Update: objItem.ExecutablePath gives the file location of the exe

luc
+1 as Nikki stated: 'great script' :-)
Blauohr
A: 

Your script is great, but I have another question. Is there a way to get file location of objItem?

See my update! Please use comments rather than adding another answer when you want some details for a specific answer
luc
A: 

I tried this code on Win XP, but it doesn`t work. Anybody know how to adapt it to XP?