argumentum

Emergency ProcessClose all scripts

1 post in this topic

#1 ·  Posted (edited)

Today I had to reboot my PC, due to something I did not see in time, again.
So I wrote a, for emergencies, close all scripts, script.
Not much code wise but handy to have compiled and running at PC's startup. Just in case... .

If Not @Compiled Then Opt("MustDeclareVars", 1) ; this script is meant to run compiled, as Admin if possible.

Global $sSelfHiddenTitle = "~~~" & StringTrimRight(@ScriptName, 4) & "~~~"
If WinExists($sSelfHiddenTitle) Then
    HotKeyPressed()
    MsgBox(262144 + 64, "Emergency Close ALL Autoit processes for user " & @UserName, 'press "Ctrl - Alt - Shift - PAUSE" to execute emergency ProcessClose', 15)
    Exit 2
EndIf

AutoItWinSetTitle($sSelfHiddenTitle & @AutoItPID & "~~~")

HotKeySet("!+^{PAUSE}", "HotKeyPressed") ; Alt-Ctrl-Shift-Pause

Opt("TrayMenuMode", 3)
Global $idCloseEmAll = TrayCreateItem("-= Emergency close all AU3s (Shift-Ctrl-Alt-Pause or DoubleClick tray icon) =-")
TrayCreateItem("") ; Create a separator line.
Global $idProcessCloseAllAutoit3 = TrayCreateItem('ProcessClose( all "Autoit3 Process" ) - for au3''s')
TrayCreateItem("")
Global $idCloseAllHiddenWin = TrayCreateItem('WinClose( all "AutoIt v3" hidden windows ) - for compiled or not')
TrayCreateItem("")
Global $idKillAllWin_CLASS_AutoItv3 = TrayCreateItem('WinKill( all "CLASS:AutoIt v3" ) - KILL''EM ALL !') ;
TrayCreateItem("")
Global $idBrowseFolderSelf = TrayCreateItem("Browse self folder")
TrayCreateItem("")
Global $idExit = TrayCreateItem("Exit")
TrayCreateItem("")
Global $idCancel = TrayCreateItem("Cancel")
TraySetState(1) ; Show the tray menu.
TraySetClick(16) ; 16 = Releasing secondary mouse button

TraySetToolTip("Emergency close ALL AutoIt's" & @CR & "by DoubleClick or Shift-Ctrl-Alt-Pause" & @CR & "RightClick for menu" & @CR & @CR & @CR & " ")

Global Const $TRAY_EVENT_PRIMARYDOUBLE = -13

main()
Func main()
    While 1
        Switch TrayGetMsg()
            Case $idCloseEmAll, $TRAY_EVENT_PRIMARYDOUBLE ;
                If HotKeyPressed() = 0 Then
                    While f_CloseAllHiddenWin()
                        Sleep(2000)
                    WEnd
                    ToolTip('Done with "AutoIt v3"', 50, 50, "Emergency close !", 1)
                    Sleep(2000)
                    ToolTip("")
                EndIf

            Case $idProcessCloseAllAutoit3
                HotKeyPressed()

            Case $idCloseAllHiddenWin
                While f_CloseAllHiddenWin()
                    Sleep(2000)
                WEnd
                ToolTip('Done with "AutoIt v3"', 50, 50, "Emergency close !", 1)
                Sleep(2000)
                ToolTip("")

            Case $idKillAllWin_CLASS_AutoItv3
                While f_idKillAllWin_CLASS_AutoItv3()
                    Sleep(2000)
                WEnd
                ToolTip('Done with "CLASS:AutoIt v3"', 50, 50, "Emergency close !", 1)
                Sleep(2000)
                ToolTip("")

            Case $idExit
                Return

            Case $idBrowseFolderSelf
                ShellExecute(@ScriptDir)

        EndSwitch
    WEnd
EndFunc   ;==>main

Func HotKeyPressed()
    Local $i = 0
    ToolTip("ProcessClose: AutoIt3 # " & $i, 50, 50, "Emergency close !", 1)
    Do
        While ProcessExists("Autoit3.exe")
            $i += 1
            ToolTip("ProcessClose: AutoIt3.exe # " & $i, 50, 50, "Emergency close !", 1)
            ProcessClose("AutoIt3.exe")
        WEnd
        While ProcessExists("AutoIt3_x64.exe")
            $i += 1
            ToolTip("ProcessClose: AutoIt3_x64.exe # " & $i, 50, 50, "Emergency close !", 1)
            ProcessClose("AutoIt3_x64.exe")
        WEnd
        Sleep(2000)
    Until (Not ProcessExists("AutoIt3.exe") And Not ProcessExists("AutoIt3_x64.exe"))
    ToolTip("")
    Return $i
EndFunc   ;==>HotKeyPressed

Func f_idKillAllWin_CLASS_AutoItv3()
    Local $n, $i = 0, $aWinList = WinList("[CLASS:AutoIt v3]")
    ToolTip(' WinKill: ' & UBound($aWinList) - 1 & ' "CLASS:AutoIt v3" ', 50, 50, "Emergency close !", 1)
    For $n = 1 To UBound($aWinList) - 1
        If StringInStr($aWinList[$n][0], $sSelfHiddenTitle) Then ContinueLoop
        WinKill($aWinList[$n][1])
        $i += 1
    Next
    Return $i
EndFunc   ;==>f_idKillAllWin_CLASS_AutoItv3

Func f_CloseAllHiddenWin()
    Local $n, $i = 0, $aWinList = WinList("AutoIt v3")
    ToolTip(' WinClose: ' & UBound($aWinList) - 1 & ' "AutoIt v3" ', 50, 50, "Emergency close !", 1)
    For $n = 1 To UBound($aWinList) - 1
        WinClose($aWinList[$n][1])
        $i += 1
    Next
    Return $i
EndFunc   ;==>f_CloseAllHiddenWin

 It eventually happens, so if it ever does, you're ready.  ;)

Edit (2017.01.27): Added, in case of "is compiled, better close all AutoIt v3 hidden windows" and "OMG, kill all [CLASS:AutoIt v3] windows". Also added double click the tray icon to execute.

Edited by argumentum
updated the script
1 person likes this

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now