r/AutoHotkey • u/duscorules • 5d ago
v2 Script Help Close all CMD windows ?
How can i create a script that will close all open CMD (command prompt) windows, using the shortcut CTRL + ALT + W ?
4
Upvotes
3
u/CharnamelessOne 5d ago
The Beginner tutorial will tell you how to make a hotkey.
WinGetList will get you an array of the handles of all the cmd windows, given an identifier called
WinTitle.You can get that identifier via WindowSpy, AHK's built-in tool. Using the process name, the class name or both is the most sensible option, most of the time.
A For loop can be used to perform an action on every item of the array returned by
WinGetList.That action should be WinClose.
3
u/Keeyra_ 5d ago
May be a bit too much for a noobie, to consider the edge cases like old windows cmd.exe vs. terminal. WinClose with ProcessClose fallback, so:
2
u/faz712 5d ago
taskkill /f /im wt.exe /im cmd.exe😂
1
u/bceen13 5d ago
Instead of using a shortcut, use the
WinClosecommand/function. The key isWinTitle. Every window has anahk_exeidentifier.