[Tutor] working w/ processes?

Scott Widney SWidney@ci.las-vegas.nv.us
Wed Feb 19 22:06:02 2003


> Solution for this on Windows is to use WMI. Sorry for the
> example in JScript (didn't have time to fully re-tool to
> Python), but translating to Python should be a piece of cake
> for which unfortunatley I will not have time, for quite some
> time :-(
> 

I don't have the time to fully translate the JScript version either, but
here is the core functionality:

####
import sys, win32com.client

wmiService =
win32com.client.GetObject("winmgmts:{impersonationLevel=impersonate,(Debug)}
")
for arg in sys.argv:
    processes = wmiService.ExecQuery("Select * from Win32_Process where
name='%s'" % arg)
    for process in processes:
        try: process.terminate()
        except: continue
####


Scott