VAN0 Posted October 14, 2017 Posted October 14, 2017 (edited) Hello. I have a program XX that asks for user confirmation on exit, which hangs the system reboot/shutdown process until I confirm. So I decided create a autoit script that would automatically close that dialog and let the system reboot/shutdown. The problem I'm facing is that my scripts now exits before the XX. Is there a way delay script exit until the XX is closed but only when system is rebooting/shutting down? Thank you. Edited November 1, 2017 by VAN0
IanN1990 Posted October 16, 2017 Posted October 16, 2017 (edited) Is this what you are after? expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Global $g_hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 200, 200) Local $idButton = GUICtrlCreateButton('', 73, 62, 54, 54, $BS_ICON) GUICtrlSetImage(-1, @SystemDir & '\shell32.dll', 45) GUICtrlSetTip(-1, 'Log off ' & @UserName) Local $idCheck = GUICtrlCreateCheckbox('Block Windows shutdown', 10, 173, 144, 21) GUIRegisterMsg($WM_QUERYENDSESSION, 'WM_QUERYENDSESSION') GUISetState(@SW_SHOW) ; Set the highest shutdown priority for the current process to prevent closure the other processes. _WinAPI_SetProcessShutdownParameters(0x03FF) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton Shutdown(0) Case $idCheck If GUICtrlRead($idCheck) = $GUI_CHECKED Then _WinAPI_ShutdownBlockReasonCreate($g_hForm, 'This application is blocking system shutdown because the saving critical data is in progress.') Else _WinAPI_ShutdownBlockReasonDestroy($g_hForm) EndIf EndSwitch WEnd Func WM_QUERYENDSESSION($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Switch $hWnd Case $g_hForm If _WinAPI_ShutdownBlockReasonQuery($g_hForm) Then ;Run your code here Return 0 EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_QUERYENDSESSION Edited October 16, 2017 by IanN1990
VAN0 Posted October 28, 2017 Author Posted October 28, 2017 (edited) Thank you! It works now. All I needed was this: #include <WinAPISys.au3> _WinAPI_SetProcessShutdownParameters(0x0100) Edited October 28, 2017 by VAN0
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