#include #RequireAdmin GUIRegisterMsg($WM_QUERYENDSESSION, "Detect_Shutdown") GUICreate("PreventShutdownGUI") GUISetSTate(@SW_HIDE) ; set highest notification level If Not _SetProcessShutdownParameters(0xFFF) Then ; MSDN says maximum is 0x4FF, but it worked for me If Not _SetProcessShutdownParameters(0x4FF) Then ; MSDN says this is reserved for System, but worked for me _SetProcessShutdownParameters(0x3FF) ; highest not reserved number, if everything else does not work EndIf EndIf While True Sleep(25) WEnd ;*********************************************************************************************************************************** Func Detect_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) ;*********************************************************************************************************************************** _WriteLog("Shutdown or Reboot Detect",True,@ScriptDir & "\test.txt") EndFunc ;*********************************************************************************************************************************** Func _SetProcessShutdownParameters($dwLevel, $dwFlags=0) ;*********************************************************************************************************************************** ; http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx ; Prog@ndy Local $aResult = DllCall("Kernel32.dll", "int", "SetProcessShutdownParameters", "dword", $dwLevel, "dword", $dwFlags) If @error Then Return SetError(1,0,0) Return $aResult[0] EndFunc ;*********************************************************************************************************************************** Func _WriteLog($Msg_Func,$DateTime_Func,$Path_LogFile_Func) ;*********************************************************************************************************************************** $DateTimeNow = @MDAY & "/" & @MON & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " : " Local $file = FileOpen($Path_LogFile_Func, 1) if $DateTime_Func = True Then FileWrite($file,$DateTimeNow & $Msg_Func & @CRLF) Else FileWrite($file,$Msg_Func & @CRLF) EndIf FileClose($file) EndFunc