On 06/08/2010 8:10 PM, Stef Mientki wrote:
  thanks,

On 06-08-2010 15:37, sharpblade wrote:
You are not using the WMI efficiently. You iterate over every process to test 
if only one is
there, when you can use WMI like so:

import wmi
x = wmi.WMI()
x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")
[<_wmi_object: \\TOM-PC\root\cimv2:Win32_Process.Handle="7052">]
def test():
t1 = time.time()
x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")
print time.time()-t1

import time
test()
0.0829999446869


but that looks quit more complicated than psutils,
besides that I believe that psutils is platform independant.

Well, just to phrase is slightly differently:

<code>
import wmi

c = wmi.WMI ()
for p in c.Win32_Process (Name="xchat.exe"):
  print p
  break
else:
  print "Not found"

</code>

TJG

_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to