sharpharp Posted March 10, 2010 Share Posted March 10, 2010 Hi all, I've editing the below script found on this forum, to intercept the logout and shutdown windows processes, and run a vbscript, but doesn't quite work. I can get it to run the vbscript, but it just runs several copies of the vbscript because it is inside a loop, could anyone please help me to get it working? expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=logoffblock.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** $WM_QUERYENDSESSION = 0x11 GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_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 Global $b_ShutdownInitiated = False ConsoleWrite("b_shutdowninitiated value is " & $b_shutdowninitiated & @CRLF) While 1 If $b_ShutdownInitiated = True then ;~ $b_ShutdownInitiated = False $b_ShutdownInitiated = True Continue_Shutdown() Else $b_ShutdownInitiated = False EndIf ;sleep(10000) WEnd Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) $b_ShutdownInitiated = True ; DO NOT ADD A MSGBOX HERE ; Windows shows a not responding box after ~5 secs and allows to kill your app. Return False EndFunc Func Continue_Shutdown();($hWndGUI, $MsgID, $WParam, $LParam) Global $WM_QUERYENDSESSION = "" $b_ShutdownInitiated = True ShellExecute("C:\hello.vbs") sleep(10000) ShellExecute("logoff.exe") ; DO NOT ADD A MSGBOX HERE ; Windows shows a not responding box after ~5 secs and allows to kill your app. Return True 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 Link to comment Share on other sites More sharing options...
Juvigy Posted March 10, 2010 Share Posted March 10, 2010 Put one "Exitloop" or maybe even "Exit" after the Continue shutdown function. If $b_ShutdownInitiated = True then ;~ $b_ShutdownInitiated = False $b_ShutdownInitiated = True Continue_Shutdown() Exitloop Link to comment Share on other sites More sharing options...
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