Last active
June 9, 2022 10:20
-
-
Save zero-plusplus/23af37abef8eb126ae665f7e8174ba41 to your computer and use it in GitHub Desktop.
Terminates all currently running AutoHotkey scripts, including itself.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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