Jump to content

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

See running AutoHotkey scripts (and end them)


  • Please log in to reply
19 replies to this topic
TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
Very simple but useful script. It lists all the AutoHotkey scripts currently running, with a button to end any of them (or a doubleclick on the item).
It uses Titan's Anchor() function (thanks!).

DetectHiddenWindows, On

Gui, +Resize -MaximizeBox
Gui, Add, ListView, w500 h200 vlvwList hwndhlvwList gListClick, PID|Script Path|Working Set|Peak Working Set|Page File|Peak Page File
Gui, Add, Button, y+6 xp w247 hwndhRefresh gRefresh, Refresh list
Gui, Add, Button, yp x+6 wp hwndhEndProc gEndProc, End associated process

Gui, Show
Sleep 200   ;Give time for Anchor to catch on
RefreshList()
Return

GuiClose:
ExitApp

GuiSize:
    Anchor(hlvwList, "wh")
    Anchor(hRefresh, "y w0.5")
    Anchor(hEndProc, "x0.5 y w0.5")
Return

Refresh:
    RefreshList()
Return

ListClick:
    If (A_GuiEvent <> "DoubleClick")
        Return
EndProc:
    
    i := LV_GetNext()
    WinKill, % "ahk_id " AHKWindows%i%
    RefreshList()
    
Return

RefreshList() {
    Global
    
    LV_Delete()
    WinGet, AHKWindows, List, ahk_class AutoHotkey
    
    Loop %AHKWindows% {
        
        ;Get process ID
        WinGet, AHKWindows%A_Index%_PID, PID, % "ahk_id " AHKWindows%A_Index%
        GetProcessMemoryInfo(AHKWindows%A_Index%_PID)
        
        ;Get memory info
        LV_Add(0, AHKWindows%A_Index%_PID, GetScriptPathFromHwnd(AHKWindows%A_Index%)
        , Round(GetProcessMemoryInfo(0,12) / 1024) " K", Round(GetProcessMemoryInfo(0,8) / 1024) " K"
        , Round(GetProcessMemoryInfo(0,32) / 1024) " K", Round(GetProcessMemoryInfo(0,36) / 1024) " K")
    }
    
    Loop 6
        LV_ModifyCol(A_Index, "AutoHdr")
    
    ;Get columns width
    iColWidth := 0
    Loop 6 {
        SendMessage, 4125, A_Index - 1, 0,, ahk_id %hlvwList%
        iColWidth += ErrorLevel
    }
    
    ;Set main width in accordance to column width
    iWidth := iColWidth + 24
    Gui, Show, w%iWidth%
}

GetScriptPathFromHwnd(hwnd) {
    WinGetTitle, win, ahk_id %hwnd%
    Return RegExMatch(win, ".*(?= - AutoHotkey v[0-9\.]+)", ret) ? ret : win
}

GetProcessMemoryInfo(pid, info=-1) {
    Static uMemCounters := 0
    
    ;Check if we just want info from the struct
    If (info <> -1)
        Return NumGet(uMemCounters, info)
    Else {
        
        ;Open the process with PROCESS_QUERY_INFORMATION and PROCESS_VM_READ
        h := DllCall("OpenProcess", "UInt", 0x0410, "UInt", 0, "UInt", pid)
        
        ;Put info into struct
        If Not uMemCounters ;Check if it hasn't already been initialized
            VarSetCapacity(uMemCounters, 40)
        DllCall("Psapi.dll\GetProcessMemoryInfo", "UInt", h, "UInt", &uMemCounters, "UInt", 40)
        
        ;Done
        DllCall("CloseHandle", "UInt", h)
    }
}

;Anchor() by Titan
;http://www.autohotkey.com/forum/viewtopic.php?t=4348
Anchor(i, a = "", r = false) {
    static c, cs = 12, cx = 255, cl = 0, g, gs = 8, z = 0, k = 0xffff, gx = 1
    If z = 0
        VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), z := true
    If a =
    {
        StringLeft, gn, i, 2
        If gn contains :
        {
            StringTrimRight, gn, gn, 1
            t = 2
        }
        StringTrimLeft, i, i, t ? t : 3
        If gn is not digit
            gn := gx
    }
    Else gn := A_Gui
    If i is not xdigit
    {
        GuiControlGet, t, Hwnd, %i%
        If ErrorLevel = 0
            i := t
        Else ControlGet, i, Hwnd, , %i%
    }
    gb := (gn - 1) * gs
    Loop, %cx%
        If (NumGet(c, cb := cs * (A_Index - 1)) == i) {
            If a =
            {
                cf = 1
                Break
            }
            Else gx := A_Gui
            d := NumGet(g, gb), gw := A_GuiWidth - (d >> 16 & k), gh := A_GuiHeight - (d & k), as := 1
                , dx := NumGet(c, cb + 4, "Short"), dy := NumGet(c, cb + 6, "Short")
                , dw := NumGet(c, cb + 8, "Short"), dh := NumGet(c, cb + 10, "Short")
            Loop, Parse, a, xywh
                If A_Index > 1
                    av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField)
                        , d%av% += (InStr("yh", av) ? gh : gw) * (A_LoopField + 0 ? A_LoopField : 1)
            DllCall("SetWindowPos", "UInt", i, "Int", 0, "Int", dx, "Int", dy, "Int", dw, "Int", dh, "Int", 4)
            If r != 0
                DllCall("RedrawWindow", "UInt", i, "UInt", 0, "UInt", 0, "UInt", 0x0101) ; RDW_UPDATENOW | RDW_INVALIDATE
            Return
        }
    If cf != 1
        cb := cl, cl += cs
    If (!NumGet(g, gb)) {
        Gui, %gn%:+LastFound
        WinGetPos, , , , gh
        VarSetCapacity(pwi, 68, 0), DllCall("GetWindowInfo", "UInt", WinExist(), "UInt", &pwi)
            , NumPut(((bx := NumGet(pwi, 48)) << 16 | by := gh - A_GuiHeight - NumGet(pwi, 52)), g, gb + 4)
            , NumPut(A_GuiWidth << 16 | A_GuiHeight, g, gb)
    }
    Else d := NumGet(g, gb + 4), bx := d >> 16, by := d & k
    ControlGetPos, dx, dy, dw, dh, , ahk_id %i%
    If cf = 1
    {
        Gui, %gn%:+LastFound
        WinGetPos, , , gw, gh
        d := NumGet(g, gb), dw -= gw - bx * 2 - (d >> 16), dh -= gh - by - bx - (d & k)
    }
    NumPut(i, c, cb), NumPut(dx - bx, c, cb + 4, "Short"), NumPut(dy - by, c, cb + 6, "Short")
        , NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short")
    Return, true
}


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I have a few suggestions:
[*:34pb812r]Use ahk_class AutoHotkey instead of the regex " - AutoHotkey v[0-9\.]+$". This way should be more reliable, and also supports AutoHotkey_L (which appends ".Lrevision" to the version).
[*:34pb812r]Remove SetTitleMatchMode, RegEx as it is now unnecessary (otherwise you'd need to use ahk_class ^AutoHotkey$ to rule out AutoHotkeyGUI windows.) RegEx matching is less efficient.
[*:34pb812r]Don't require the assertion (?= - AutoHotkey v[0-9\.]+) to match - it won't for compiled scripts. For instance,
if !RegExMatch(win, ".*(?= - AutoHotkey v[0-9\.]+)", ret)
        ret := win
AHKControl serves a similar purpose, but also provides many other shortcuts for each script. If you'd like to use any of the ideas or code from it, feel free.

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007

I have a few suggestions:


Thanks for the suggestions! I incorporated all of them.

TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
I updated the script so that it gives memory info about the associated process of each script (Working Set, Peak Working Set, Page File, Peak Page File).

strictlyfocused02
  • Members
  • 64 posts
  • Last active: Dec 11 2015 08:35 PM
  • Joined: 21 Jan 2009
This is awesome! Extremely useful! Thank you so much!

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
It saved me a lot of time when guessing wrong in TaskManager, which entry corresponds to a hanging script, which script leaks memory. Thanks for sharing it!

trstone
  • Members
  • 9 posts
  • Last active: Aug 05 2009 10:03 PM
  • Joined: 16 Mar 2009
@thegood

fantastic program!

would you do me a solid and post an adjusted script that would allow this script to be executed from a hotkey (from another script) and go back to standby mode once the status page is closed?

thanks,
tom

trstone
  • Members
  • 9 posts
  • Last active: Aug 05 2009 10:03 PM
  • Joined: 16 Mar 2009
disregard my last ...

thanks,
tom

Metaxal
  • Members
  • 25 posts
  • Last active: Jul 05 2010 05:29 PM
  • Joined: 04 Mar 2009
Good script!

Suggestion: You could use a timer to automatically refresh the list every second or so.

trismarck
  • Members
  • 390 posts
  • Last active: Nov 25 2015 12:35 PM
  • Joined: 02 Dec 2010

Thanks for this TheGood.


New Autohotkey forum: http://ahkscript.org.


terrypin
  • Members
  • 174 posts
  • Last active: Mar 15 2017 10:00 AM
  • Joined: 10 Jul 2009

Thanks for this very handy script.

 

But I'd like to be able to use it with a hotkey so I added this second line:

DetectHiddenWindows, On	

#^F2:: ; Win + Ctl + F2 Added this to get hotkey control. But it only works once.

etc
.
.
.
        , NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short")
    Return, true
}

But the after the hotkey has been used for the first time, the script closes.

 

How do I get it to stay?  I tried the command #Persistent but that didn't work.

 

--
Terry, East Grinstead, UK



terrypin
  • Members
  • 174 posts
  • Last active: Mar 15 2017 10:00 AM
  • Joined: 10 Jul 2009

Not sure how, but this is the second time recently I've managed to send the same post twice. Is there no way to delete it, or can I only change its content, as I've done here?

 

--
Terry, East Grinstead, UK



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

 

Thanks for this very handy script.

 

But I'd like to be able to use it with a hotkey so I added this second line:

DetectHiddenWindows, On	

#^F2:: ; Win + Ctl + F2 Added this to get hotkey control. But it only works once.

etc
.
.
.
        , NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short")
    Return, true
}

But the after the hotkey has been used for the first time, the script closes.

 

How do I get it to stay?  I tried the command #Persistent but that didn't work.

 

--
Terry, East Grinstead, UK

 

Thanks for this very handy script.

 

But I'd like to be able to use it with a hotkey so I added this second line:

DetectHiddenWindows, On	

#^F2:: ; Win + Ctl + F2 Added this to get hotkey control. But it only works once.

etc
.
.
.
        , NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short")
    Return, true
}

But the after the hotkey has been used for the first time, the script closes.

 

How do I get it to stay?  I tried the command #Persistent but that didn't work.

 

--
Terry, East Grinstead, UK

could you explain what you mean by "to use it with a hotkey"?



terrypin
  • Members
  • 174 posts
  • Last active: Mar 15 2017 10:00 AM
  • Joined: 10 Jul 2009

could you explain what you mean by "to use it with a hotkey"?


Eh? I just mean that I want to be able to press a key combination (a hotkey) to see the list of current scripts.

Terry, East Grinstead, UK

bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

A new addition to my archive! ;)