Last active
April 23, 2016 11:10
-
-
Save amirhp-com/e6934714ae67e522babfabd721fc5d73 to your computer and use it in GitHub Desktop.
AU3 # Prevent Script from System Poweroff
This file contains hidden or 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
;RUNGUI() ; Remove ';' from first line , so script GUI will open | |
Func RUNGUI() | |
$WM_QUERYENDSESSION2 = 0x11 | |
GUIRegisterMsg($WM_QUERYENDSESSION2, "Cancel_Shutdown") | |
$Hwnd = GUICreate("PreventShutdownGUI") | |
GUISetSTate(@SW_SHOW) | |
MsgBox(262144,'','Hello kitty') | |
_ShutdownBlockReasonCreate($hwnd, "Please Save your work then shut ur pc down :)"&@CR&"secound line goes here") | |
TrayTip("Shutdown", "Denied shutdown for 15 seconds", 10) | |
Sleep(30000) | |
_ShutdownBlockReasonDestroy($hwnd) | |
EndFunc | |
Func _ShutdownBlockReasonCreate($Hwnd, $wStr) | |
; http://msdn.microsoft.com/en-us/library/ms...28VS.85%29.aspx | |
; Prog@ndy | |
Local $aResult = DllCall("User32.dll", "int", "ShutdownBlockReasonCreate", "hwnd", $Hwnd, "wstr", $wStr) | |
If @error Then Return SetError(1,0,0) | |
Return $aResult[0] | |
EndFunc | |
Func _ShutdownBlockReasonDestroy($Hwnd) | |
Local $aResult = DllCall("User32.dll", "int", "ShutdownBlockReasonDestroy", "hwnd", $Hwnd) | |
If @error Then Return SetError(1,0,0) | |
Return $aResult[0] | |
EndFunc | |
Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) | |
; This HAS to be here to capture the endsession... | |
; DO NOT ADD A MSGBOX HERE | |
; Windows shows a not responding box after ~5 secs and allows to kill your app. | |
Return False | |
EndFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment