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:<div><br></div><div><div>>>> import wmi</div><div>>>> x = wmi.WMI()</div><div>
>>> x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")</div><div>[<_wmi_object: \\TOM-PC\root\cimv2:Win32_Process.Handle="7052">]</div><div>>>> def test():</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>t1 = time.time()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>x.query("SELECT * FROM Win32_Process WHERE Name = 'xchat.exe'")</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>print time.time()-t1</div><div><br></div><div>>>> import time</div><div>>>> test()</div><div>0.0829999446869</div><div>>>> </div>
<div><br></div><div>You can further reduce load times by requesting less data from WMI, i.e stuff you are going to use:</div><div><div>>>> def test():</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>t1 = time.time()</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>x.query("SELECT Handle FROM Win32_Process WHERE Name = 'xchat.exe'")</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>print time.time()-t1</div>
</div><div><div>>>> test()</div><div>0.0599999427795</div></div><div><br><div class="gmail_quote">On Fri, Aug 6, 2010 at 2:27 PM, Stef Mientki <span dir="ltr"><<a href="mailto:stef.mientki@gmail.com">stef.mientki@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> thanks Tim,<br>
<div class="im"><br>
On 06-08-2010 13:44, Tim Golden wrote:<br>
> On 06/08/2010 12:27, Stef Mientki wrote:<br>
</div>> <snip<br>
<div class="im"><br>
> Try psutil (which uses the toolhelp DLL):<br>
><br>
> <a href="http://code.google.com/p/psutil/" target="_blank">http://code.google.com/p/psutil/</a><br>
><br>
> <code><br>
> import psutil<br>
><br>
> for p in psutil.process_iter ():<br>
> if <a href="http://p.name" target="_blank">p.name</a> == "blah":<br>
> print p<br>
> break<br>
> else:<br>
> print "Not found"<br>
><br>
> </code><br>
><br>
</div>yes that works quit well, just a little bit slower than AutoIt:<br>
AutoIt: 0 .. 15 msec<br>
psutils: 40 ..50 msec<br>
<br>
thanks,<br>
<font color="#888888">Stef Mientki<br>
</font><div><div></div><div class="h5">> TJG<br>
> _______________________________________________<br>
> python-win32 mailing list<br>
> <a href="mailto:python-win32@python.org">python-win32@python.org</a><br>
> <a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
<br>
_______________________________________________<br>
python-win32 mailing list<br>
<a href="mailto:python-win32@python.org">python-win32@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
</div></div></blockquote></div><br></div></div>