
t_bear
Members-
Posts
14 -
Joined
-
Last visited
t_bear's Achievements

Seeker (1/7)
0
Reputation
-
This app made as a helper app for an installation app, to block shutdown while an installation is running. But can be used as a standalone solution (but it has no visible gui, besides the /debug window) It consists of two scripts, one to block, and another to thell the blocking app to stop. Input params for shutdownblocker: shutdownblocker.exe "Title to be displayed" "Message to be displayed" [/debug]Input params for shutdownblocker_close: shutdownblocker_close.exe "title of shutdownblocker.exe" [/debug]The code can be found below, tested on WinXp with sp3 and Windows 7 64bit, with sp1 Note: For the close app to work, the scripts must be compiled. (window matching won't work if not compiled, thus the WM_CLOSE won't be recieved)Will not work if compiled as an console app.Thanks: This code was based on an example by /manko at: Thanks to /manko, Yashied and guinness for help Also a lot of thanx to Nenad from softwareok.com, for a lot of help making the Win7 solution work shutdownblocker.au3 shutdownblocker_close.au3
-
Well then, I guess I'm using a higher number in the SetProcessShutdownParameters than that other shutdownblocker, cause I'm getting those QUERYENDSESSION messages now But you're right, I did not catch that I had to use SetProcessShutdownParameters in order to recieve those QUERYENDSESSION messages at all. I guess I was fooled by the other examples at the autoit forum that didn't contain it, where they claimed it to be working. But.. it's working now, and I'll post the code when I'm done with it... If others find it useful. Thank you very much for your help
-
Thanks!!!! it was the _WinAPI_SetProcessShutdownParameters(0x03FF) that did the trick! As you said, without it, I'm just too late in queue. But no... I'm not using the WinAPI UDF, I just implemented it from your code at I also added code for windows 7 by adding : _ThreadExecutionState_Set and _ShutdownBlockReasonCreate Full code here: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..Stockage.ico #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Comment=Shutdown blocker, test app comment #AutoIt3Wrapper_Res_Description=Shutdown blocker, test app desc #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;http://www.autoitscript.com/forum/topic/133896-prevent-shutdownsleep-in-vista7/ ;by /Manko, modified by T_Bear AutoItSetOption("TrayAutoPause","0") AutoItSetOption("MustDeclareVars", True) AutoItSetOption("TrayIconHide", True) AutoItSetOption("ExpandEnvStrings", True) AutoItSetOption("TrayOnEventMode", True) #include <Debug.au3> Global Const $ES_AWAYMODE_REQUIRED=0x00000040 Global Const $ES_CONTINUOUS=0x80000000 Global Const $ES_DISPLAY_REQUIRED=0x00000002 Global Const $ES_SYSTEM_REQUIRED=0x00000001 Global Const $ES_USER_PRESENT=0x00000004 Global Const $PBT_APMSUSPEND = 0x0004 Global Const $WM_QUERYENDSESSION = 0x0011 Global Const $WM_ENDSESSION = 0x0016 Global Const $WM_POWERBROADCAST = 0x0218 Global $bQuit=False HotKeySet("^x","quit") HotKeySet("^X","quit") Global $hGUI=GUICreate("BatchExecuter-Block-Shutdown+Restart+Logoff",1,1) GUISetSTate(@SW_HIDE) _DebugSetup("BatchExecuter-Block-Shutdown+Restart+Logoff",False,1) _DebugOut ("@OSBuild: " & @OSBuild & @LF) ;_DebugOut ("@OSVersion_@OSArch: " & @OSVersion & "_" & @OSArch & @LF) ;Init/Setup if @OSBuild <= 2600 Then ;Winxp or lower Register_WM_QUERYENDSESSION() Register_SetProcessShutdownParameters() ;Register_WM_ENDSESSION() ;Register_WM_POWERBROADCAST() Else ;Vista or higher Register_WM_QUERYENDSESSION() Register_WM_ENDSESSION() Register_WM_POWERBROADCAST() Register_SetProcessShutdownParameters() Register_ShutdownBlockReason() Register_ThreadExecutionState() EndIf ;@OSVersion "WIN_2008R2", "WIN_7", "WIN_8", "WIN_2008", "WIN_VISTA", "WIN_2003", "WIN_XP", "WIN_XPe", "WIN_2000". ;Wait loop... somehow after two logoff attempts.. it stops blocking shutdown... _DebugOut("Waiting for Control+x to quit" & @LF) While 1 if $bQuit = True then ExitLoop Sleep(250) WEnd _DebugOut("Stopping Blocking shutdown, cleanup and exit." & @LF) ;Cleanup if @OSBuild <= 2600 Then ;Winxp or lower ;Nothing to do Else ;Vista or higher DeRegister_ThreadExecutionState() DeRegister_ShutdownBlockReason() EndIf ;Sleep(3000) exit 0 Func Register_WM_QUERYENDSESSION() _DebugOut("Registrering for GUIMsg WM_QUERYENDSESSION." & @LF) ;For Xp, register for WM_QUERYENDSESSION, then abort the shutdown/logoff If Not GUIRegisterMsg($WM_QUERYENDSESSION, "HANDLE_WM_QUERYENDSESSION") then ; enough for windows xp, but in Vista/7, we will add "Shutdownblockreason"... _DebugOut("Error registrering WM_QUERYENDSESSION" & @LF) Sleep(3000) EndIf EndFunc Func Register_WM_ENDSESSION() _DebugOut("Registrering for GUIMsg WM_ENDSESSION" & @LF) ;See if we can trap endsessions If Not GUIRegisterMsg($WM_ENDSESSION, "HANDLE_WM_ENDSESSION") then ; enough for windows xp, but in Vista/7, we will add "Shutdownblockreason"... _DebugOut("Error registrering WM_ENDSESSION" & @LF) Sleep(3000) EndIf EndFunc Func Register_WM_POWERBROADCAST() _DebugOut("Registrering for GUIMsg WM_POWERBROADCAST" & @LF) ; ***************** In Vista/7 there is no longer a way to prevent Sleep/hibernate instigated by user action, cause of the risk of backpack-attack.... ********* ; If Not GUIRegisterMsg($WM_POWERBROADCAST, "HANDLE_WM_POWERBROADCAST") THEN ; But we still have about 2secs to do some cleanup... _DebugOut("Error registrering WM_POWERBROADCAST" & @LF) Sleep(3000) EndIf EndFunc Func Register_SetProcessShutdownParameters() _DebugOut("Setting ProcessShutdownParameters" & @LF) ; We wanna be first in the queue when notifications come about shutdown/sleep... If Not _SetProcessShutdownParameters(0xFFF) Then ; MSDN says maximum is 0x4FF, but it worked for me (Prog@ndy) _DebugOut("Error setting SetProgressShutdownParameters to 0xFFF (try1/4)" & @LF) Sleep(3000) If Not _SetProcessShutdownParameters(0x4FF) Then ; MSDN says this is reserved for System, but worked for me (Prog@ndy) _DebugOut("Error setting SetProgressShutdownParameters to 0x4FF (try2/4)" & @LF) Sleep(3000) If Not _SetProcessShutdownParameters(0x3FF) Then ; highest not reserved number, if everything else does not work _DebugOut("Error setting SetProgressShutdownParameters to 0x3FF (try 3/4)" & @LF) Sleep(3000) if Not _SetProcessShutdownParameters(0x300) Then ; _DebugOut("Error setting SetProgressShutdownParameters to 0x3FF (try 4/4), total falure, cannot control if apps are closed under windows vista/7." & @LF) Sleep(3000) EndIf EndIf EndIf EndIf EndFunc Func Register_ShutdownBlockReason() _DebugOut("Setting ShutdownBlockReason" & @LF) ; without this, computer will sometimes shutdown but sometimes be saved by the app_unresponsive screen after some or no apps close... ; The descriptive text should be short and to the point or users might ignore.... if not _ShutdownBlockReasonCreate($hGUI,"WARNING: Software job in progress. Do not shutdown, reboot or logoff your computer! Doing so may harm the computer.") Then _DebugOut("Error setting _ShutdownBlockReasonCreate" & @LF) Sleep(3000) EndIf EndFunc Func Register_ThreadExecutionState() _DebugOut("Setting TreadExecutionState" & @LF) ;To prevent sleep, telling the OS that we're running an app that cannot be interrupted ;The ES_AWAYMODE_REQUIRED value should be used only when absolutely necessary by media applications that require the system ;to perform background tasks such as recording television content or streaming media to other devices while the system appears to be sleeping If Not _ThreadExecutionState_Set() Then _DebugOut("Error setting _ThreadExecutionState_Set" & @LF) Sleep(3000) EndIf EndFunc Func DeRegister_ThreadExecutionState() _DebugOut("Disabling ThreadExecutionState" & @LF) if not _ThreadExecutionState_Disable() Then _DebugOut("Error setting _ThreadExecutionState_Disable" & @LF) Sleep(3000) EndIf EndFunc Func DeRegister_ShutdownBlockReason() _DebugOut("Disabling ShutdownBlockReason" & @LF) if not _ShutdownBlockReasonDestroy($hGUI) Then _DebugOut("Error setting _ThreadExecutionState_Disable" & @LF) Sleep(3000) EndIf EndFunc Func HANDLE_WM_QUERYENDSESSION($hWndGUI, $MsgID, $WParam, $LParam) ; DO NOT ADD A MSGBOX HERE ; Windows shows a not responding box after ~5 secs and allows to kill your app. ; ; http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx#CommunityContent' ; $LParam: ; ENDSESSION_CLOSEAPP ; 0x00000001 The application is using a file that must be replaced, the system is being serviced, or system resources are exhausted. For more information, see Guidelines for Applications. ; ; ENDSESSION_CRITICAL ; 0x40000000 The application is forced to shut down. ; ; ENDSESSION_LOGOFF ; 0x80000000 The user is logging off. For more information, see Logging Off. _DebugOut("WM_QUERYENDSESSION, cancel session change: " & $LParam & @LF) Return False ; DO NOT SHUTDOWN EndFunc Func HANDLE_WM_ENDSESSION($hWndGUI, $MsgID, $WParam, $LParam) ; DO NOT ADD A MSGBOX HERE ; Windows shows a not responding box after ~5 secs and allows to kill your app. ; ; http://msdn.microsoft.com/en-us/library/aa376889(v=vs.85).aspx ; $LParam: ; ENDSESSION_CLOSEAPP ; 0x00000001 The application is using a file that must be replaced, the system is being serviced, or system resources are exhausted. For more information, see Guidelines for Applications. ; ; ENDSESSION_CRITICAL ; 0x40000000 The application is forced to shut down. ; ; ENDSESSION_LOGOFF ; 0x80000000 The user is logging off. For more information, see Logging Off. _DebugOut("WM_ENDSESSION, system going down. " & $LParam & @LF) Return False ; DO NOT SHUTDOWN EndFunc Func HANDLE_WM_POWERBROADCAST($hwnd, $msg, $wparam, $lparam) _DebugOut("WM_POWERBROADCAST recieved!" & @LF) if $wparam=$PBT_APMSUSPEND then ; We have about 2 secs... ; Do some cleanup! ; ...or whatever _DebugOut("WM_POWERBROADCAST, Shutdown with powerbutton, do cleanup within 2 sec's, cause then you'll die!" & @LF) EndIf Return 1 ;Try to cancel the powerbroadcast. 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 _ShutdownBlockReasonCreate($Hwnd, $wStr) 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 _ThreadExecutionState_Set() ;The ES_AWAYMODE_REQUIRED value should be used only when absolutely necessary by media applications that require the system ;to perform background tasks such as recording television content or streaming media to other devices while the system appears to be sleeping Local $aResult = DllCall("kernel32.dll", "int", "SetThreadExecutionState", "int", BitOR($ES_CONTINUOUS, $ES_SYSTEM_REQUIRED, $ES_AWAYMODE_REQUIRED)) ;$ES_AWAYMODE_REQUIRED if @error Then Return SetError(1,0,0) Return $aResult[0] EndFunc Func _ThreadExecutionState_Disable() ;// Clear EXECUTION_STATE flags to disable away mode and allow the system to idle to sleep normally. Local $aResult = DllCall("kernel32.dll", "int", "SetThreadExecutionState", "int", $ES_CONTINUOUS) if @error Then Return SetError(1,0,0) Return $aResult[0] EndFunc Func quit() $bQuit=True EndFunc
-
I did search (for several days actually), And I've tried most of the scripts containing the GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") As pointed out by adom in this post: the VM_QUERYENDSESSION is no longer recognized/recieved by autoit. Seems to me that this is a bug,the VM_QUERYENDSESSION and VM_ENDSESSION, is not recieved by autoit in WinXp (with sp3), but is recieved in Windows 7 (64bit with sp1), using the exact same code.
-
I'm trying to prevent accidental logoff/shutdown/restart while an install is running, but cannot make this work on WinXp with Service Pack 3 Seems to me that autoit no longer recieves WM_QUERYENDSESSION messages for WinXp. Tried the same code in Windows 7 (64bit with SP1), and there we get the QUERYENDSESSION message. (even though you have to do a bit more for win7 to block shutdown, but that's beside the point) Is there any other way I can run GUIRegisterMsg to try getting those WM_QUERYENDSESSION messages? Opt("TrayIconHide", 1) $WM_QUERYENDSESSION = 0x11 GUICreate("PreventShutdownGUI") GUISetSTate(@SW_HIDE) GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") ConsoleWrite("wait forever" & @CRLF) While 1 sleep(100) WEnd exit 0 Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) ConsoleWrite("Prevent shutdown" & @CRLF) Return False EndFunc Best regards T_Bear
-
Hi. Some of you may have been using CCM/iCommand/LiveState Delivery and used the buttonpusher that comes with it. (Transcript Recorder) Now the product has been end-of-life'd, and I wanted to continue to use the transcript recorder language in our next installation system. (we have a LOT of buttonpusher scripts... and the language is really easy to use) So I've created in AutoIt a .win parser that reads the .win files (not the compiled .if files that wininter.exe does) and does the same thing. It's not complete yet, but it's getting there. Here's what a .win file could look like: [preface] language = 0 version = 0, 1 [variables] INSTALLPATH = "C:\\Program Files\\Demo\\" [begin] RUN "C:\\Doc\\AutoIt\\WinFileParser\\demo.exe" [windows] {"Demo"} {"~This program will demonstrate " , "~Welcome to the demonstration i"} [ BUTTON {"Next >"|"&Next >"} SLEEP 1 ] WB1:{"Demo"} {"Destination Folder" , "Install Demo to:"} ! WB1 [ BUTTON {"Change..."|"&Change..."} ] {"Demo"} {"Look in:" , "&Look in:"} [ EDIT {"#731"} <INSTALLPATH> BUTTON {"OK"|"&OK"} ] WB2:{"Demo"} {"Destination Folder" , "Install Demo to:"} ! WB2 & WB1 [ BUTTON {"Next >","&Next >"} ] {"Demo"} {"Ready to Install the Program"} [ BUTTON {"Install"|"&Install"} ] {"Demo"} {"InstallShield Wizard Completed"} [ BUTTON {"Finish"|"&Finish"} end ] Anyone interested in this? Quite often, silent params just don't work, or works differently than you want it to, and then this way of telling a buttonpusher what to do, just make life sooo much easyer Best regards T-Bear
-
Works great! Even has diff in time (this makes my job sooooo much easyer) Thanks Thorbjørn
-
Thanx, I'll test it! Best regards Thorbjørn
-
Hi.. I really need this function, and it's great, but there's a bug in it. I tried using $a = ddays(20041231, 20050101) as input.. well it craches.. It crashes if month number 12 is used in the first parameter (any day), but works fine if you use month 12 in the secound parameter instead. Can you fix it? Please? Best regards Thorbjørn Skistad