[python-win32] fast test if (unknown) process is running ? Why not use Autoit ?
mail at timgolden.me.uk
Fri Aug 6 21:18:49 CEST 2010
On 06/08/2010 8:10 PM, Stef Mientki wrote:
> 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
> but that looks quit more complicated than psutils,
> besides that I believe that psutils is platform independant.
Well, just to phrase is slightly differently:
c = wmi.WMI ()
for p in c.Win32_Process (Name="xchat.exe"):
print "Not found"
More information about the python-win32