Skip to content

Instantly share code, notes, and snippets.

@zero-plusplus
Last active June 9, 2022 10:20
Show Gist options
  • Save zero-plusplus/23af37abef8eb126ae665f7e8174ba41 to your computer and use it in GitHub Desktop.
Save zero-plusplus/23af37abef8eb126ae665f7e8174ba41 to your computer and use it in GitHub Desktop.
Terminates all currently running AutoHotkey scripts, including itself.
/**
* @author zero-plusplus (https://github.com/zero-plusplus)
* @licence MIT
* @link https://gist.github.com/zero-plusplus/23af37abef8eb126ae665f7e8174ba41
*/
/**
* Terminates all currently running AutoHotkey scripts, including itself.
* @param {boolean} [excludeSelf := false] - Excludes the current script from processing
*/
KillAllAutoHotkey(excludeSelf := false) {
bk := A_DetectHiddenWindows
DetectHiddenWindows, On
WinGet, currentScriptPid, PID, ahk_id %A_ScriptHwnd%
WinGet, autohotkeyList, List, ahk_class AutoHotkey
length := autohotkeyList
Loop %length% {
hwnd := autohotkeyList%A_Index%
WinGet, pid, PID, ahk_id %hwnd%
if (currentScriptPid == pid) {
continue
}
Process, Close, %pid%
}
DetectHiddenWindows, %bk%
if (!excludeSelf) {
ExitApp
}
}
/**
* @author zero-plusplus (https://github.com/zero-plusplus)
* @licence MIT
* @link https://gist.github.com/zero-plusplus/23af37abef8eb126ae665f7e8174ba41
*/
/**
* Terminates all currently running AutoHotkey scripts, including itself.
* @param {boolean} [excludeSelf := false] - Excludes the current script from processing
*/
KillAllAutoHotkey(excludeSelf := false) {
bk := A_DetectHiddenWindows
DetectHiddenWindows(true)
currentScriptPid := WinGetPID("ahk_id " A_ScriptHwnd)
for i, hwnd in WinGetList("ahk_class AutoHotkey") {
pid := WinGetPID("ahk_id " hwnd)
if (currentScriptPid == pid) {
continue
}
ProcessClose(pid)
}
DetectHiddenWindows(bk)
if (!excludeSelf) {
ExitApp
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment