[python-win32] Listing all processes
fuzzyman at voidspace.org.uk
Tue Jun 12 16:56:09 CEST 2007
Tim Golden wrote:
> Michael Foord wrote:
>> I recently blogged about how listing all running processes is easy
>> with IronPython .
>> Can anyone suggest a better solution? (DISCLAIMER: I didn't write
>> this, my colleagues 'borrowed' it from the intarwebz.)
> (Hmmm. Bit defensive there, Mr F.... :)
>> # check if AVG and Thunderbird are running
>> import win32pdhutil
>> for procName in ['avgwa.dat', 'avgw', 'thunderbird', "THUNDE~1"]:
>> win32pdhutil.GetPerformanceAttributes('Process','ID Process',
>> if win32pdhutil.FindPerformanceAttributesByName(procName):
>> print "Pylint error found: Please shut down %s" % procName
>> from System.Diagnostics import Process
>> procs = Process.GetProcesses()
>> print "All running processes:"
>> print '\n'.join(proc.ProcessName for proc in procs)
> [WMI using pywin32]
> import win32com.client
> wmi = win32com.client.GetObject ("winmgmts:")
> procs = wmi.InstancesOf ("Win32_Process")
> print "\n".join (proc.Properties_ ("Caption").Value for proc in procs)
> [WMI using wmi module]
> import wmi
> procs = wmi.WMI ().Win32_Process ()
> print "All running processes:"
> print "\n".join (proc.Caption for proc in procs)
> In fact, putting your subject line plus "Python" into
> Google, these solutions (in different forms) appear third
> and sixth in the results list.
Well, your suggestions are definitely better than what we are using. :-)
Now this is why I was defensive...
More information about the Python-win32