Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

List Running Processes [AHK_L]


  • Please log in to reply
4 replies to this topic
shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
Shorter code to list running processes than given in the documentation (http://www.autohotke...nds/Process.htm) using AHK_L

strComputer := "."
objWMIService := ComObjGet("winmgmts:\\" . strComputer . "\root\cimv2")
colProcesses := objWMIService.ExecQuery("Select * From Win32_Process")._NewEnum

Gui, Add, ListView, x2 y0 w400 h500 vMyLV,Process Name|WorkingSetSize|Priority|ThreadCount
GuiControl, -Redraw, MyLV 

While colProcesses[objProcess]
	LV_Add("",objProcess.Name , objProcess.WorkingSetSize , objProcess.Priority , objProcess.ThreadCount)

GuiControl, +Redraw, MyLV 
LV_ModifyCol(1,160)
Gui, Show, w400 h500, Process List
Return

GuiClose:
ExitApp


Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
Out of curiosity I did some speed tests.
The documented code on AHK Basic takes 0.042471 seconds to run.
The same code on AHK_L takes 0.021885 seconds to run.
And your code with changes to make it more like the above code takes 0.252985 seconds.

I was surprised to see that its slower.

Heres the code used to speed test it:
While QPX(100)
	P()
Msgbox % QPX()

P()
{
	strComputer := "."
	objWMIService := ComObjGet("winmgmts:\\" . strComputer . "\root\cimv2")
	colProcesses := objWMIService.ExecQuery("Select * From Win32_Process")._NewEnum

	While colProcesses[objProcess]
	   List .= objProcess.Name "|" objProcess.WorkingSetSize "|" objProcess.Priority "|" objProcess.ThreadCount "`n"
}
QPX can be found here -> <!-- m -->http://www.autohotke...topic52083.html<!-- m -->
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Generally more abstraction = slower. WMI probably just wraps those other APIs in some of its own logic; i.e. it does more work to the same effect.

Btw, after the next update you should be able to remove ._NewEnum and do:
for process in colProcesses
At the moment the for-loop calls ._NewEnum(), which doesn't work in this case.

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
Well its good to see that _L can run the same script in the docs about twice as fast.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
You could probably get the same speed-up in AutoHotkey Basic by resolving the dll function names using GetModuleHandle/GetProcAddress before-hand and calling by address instead of by name.