ProgAndy Posted January 27, 2010 Posted January 27, 2010 So how would I set $WM_QUERYENDSESSION to trueAre you registering 0x11 to query your script every time a shutdown is called?And then through that, it calls the cancel_shutdown function?So if I wanted to have a conditional shutdown, I could put an in statement in the cancel_shutdown function and have it return true or false?True. Returning False prevents the shutdown, true allows to resume. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
gte Posted January 27, 2010 Posted January 27, 2010 Thanks Andy Here is what I modded it to, you have an input box and the input box value determines a variable which allows you to bypass the script, but you have to click log off twice to actually log off. Is there any way to have the logoff/shutdown command paused, and then wait for the input box value before decided what to do, then continuing on to what the user initially requested if they pass the input box check, say with a do ... until? I tried a do ... until at the top of the Cancel_Shutdown function and windows continued to try and shutdown, so maybe there is a way to catch the users request, be it a shutdown or restart and then input it for them programmatically? expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $WM_QUERYENDSESSION = 0x11 GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") GUICreate("PreventShutdownGUI") GUISetSTate(@SW_HIDE) Global $pinentered = 0 ; 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 Global $b_ShutdownInitiated = False While 1 $nMsg = GUIGetMsg() If $b_ShutdownInitiated = True then $b_ShutdownInitiated = False $pininput = InputBox("Log Off Verification", @crlf & @crlf & "Please type your pin in, to verify that you definitely want to log off or shutdown." & @CRLF & @CRLF & "Then click logoff or shutdown once more, after verifying this is the intended action.", "", "", 500, 200) If StringLen($pininput) = 6 Then ; conditional inputbox $pinentered = 1 ; value that keeps the script from catching itself in function Cancel_Shutdown() ConsoleWrite("Pin length correct, pin is " & $pininput & @crlf) Else ConsoleWrite("Pin length incorrect" & @crlf) EndIf EndIf sleep(10) WEnd Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) If $pinentered = 0 Then $b_ShutdownInitiated = True FileWriteLine("c:\temp\logoff_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- ") FileWriteLine("c:\temp\logoff_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- " & @UserName & " almost accidentially logged off this pin or shutdown this box down") FileWriteLine("c:\temp\logoff_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- ") ; DO NOT ADD A MSGBOX HERE ; Windows shows a not responding box after ~5 secs and allows to kill your app. Return False ElseIf $pinentered = 1 Then $b_ShutdownInitiated = False FileWriteLine("c:\temp\logoff_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- ") FileWriteLine("c:\temp\logoff_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- " & $pininput & " logged off this pin or shutdown this box down") FileWriteLine("c:\temp\logoff_log.txt", @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ---- ") ; DO NOT ADD A MSGBOX HERE ; Windows shows a not responding box after ~5 secs and allows to kill your app. Return True EndIf 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 HP OpenView ServiceCenter keep alive scriptRemote Desktop Login Script
Pardalito Posted February 11, 2010 Posted February 11, 2010 Hello,I used this function many times and work great, but now with Windows 7 I have a little problem.I have an AutoIt script that runs 2 childs processes, httpd.exe and mysqld.exe.When a try to shutdown Windows 7, this function blocks the shutdown correctly, but kills the 2 childs processes (httpd.exe and mysqld.exe).In Windows XP this problem doesn’t happens. Blocks shutdown and the 2 childs processes still running correctly.Using the _ShutdownBlockReasonCreate method.Any idea to prevent the kill of this 2 childs processes in Win 7?Thanks.
Pardalito Posted February 11, 2010 Posted February 11, 2010 Sorry... Forgot to define shutdown high priority. 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 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 Solved !!! Thanks, Pardalito.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now