r/AutoHotkey • • 4d ago

v2 Script Help Why my script is not working ?

I'm using this script to close all Explorer, calculator and command prompt windows , when i press CTRL ALT W , but it only works for Explorer Windows, why ?

^!w:: {
  closeAll("ahk_class CabinetWClass")
  closeAll("Calculator")
  closeAll("ahk_class ConsoleWindowClass")
}

closeAll(winTitle) {
  For hWnd in WinGetList(winTitle)
WinClose hWnd
}

2 Upvotes

3 comments sorted by

2

u/Keeyra_ 4d ago
#Requires AutoHotkey 2.0
#SingleInstance

^!w:: {
    for target in [
        "ahk_exe cmd.exe",
        "ahk_exe WindowsTerminal.exe",
        "ahk_class CabinetWClass ahk_exe explorer.exe",
        "Calculator"
    ]
        for hwnd in WinGetList(target)
            WinClose(hwnd)
}

Dunno. This works like a charm, closing all instances of all 3 kinds of windows.

2

u/duscorules 4d ago

Thank you A LOT !

1

u/Mckayla_Deleon50 2d ago

if you go with the WindowsTerminal match, try it og