gte Posted January 25, 2010 Share Posted January 25, 2010 We have a few servers that are required to end the session (clicking on the X in the remote desktop window), instead of logging off, and a few that are required to log off instead of ending the session. Can this be monitored and prevented through event manager entries? Or any ideas? This script blocks log offs, and could be modded to work I think, but I don't understand the entire script expandcollapse popup#include <ie.au3> #include <GUIConstantsEx.au3> $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 While 1 If $b_ShutdownInitiated = True then $b_ShutdownInitiated = False EndIf sleep(10) 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 _SetProcessShutdownParameters($dwLevel, $dwFlags=0) ; http://msdn.microsoft.com/en-us/library/ms...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 Link to comment Share on other sites More sharing options...
gte Posted January 25, 2010 Author Share Posted January 25, 2010 Where is b_ShutdownInitiated defined and how do you have it effect logoff, but not shutdown? HP OpenView ServiceCenter keep alive scriptRemote Desktop Login Script Link to comment Share on other sites More sharing options...
gte Posted January 25, 2010 Author Share Posted January 25, 2010 I'm close for the first one I think, I just cannot get it to continue past the shutdown catch, if you verify that you actually want it to shut down? Any ideas? 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 $messageboxbutton = MsgBox(5 + 48 + 8192 + 262144, "Error", "Logging Off has been disabled as a service is dependent on this ERE pin you are logged in as." _ & @CRLF & @CRLF & "You must click on the Remote Desktop 'X' to close the window, but leave the session open." _ & @CRLF & @CRLF & "If you are SURE you want to log off, click retry and enter your pin, if you don't want to log off after all, click cancel") ConsoleWrite("About to enter switch statement" & @crlf) Switch GUIGetMsg($messageboxbutton) ConsoleWrite("Message box button value is " & $messageboxbutton & @CRLF) Case $messageboxbutton = 4 ; retry ConsoleWrite("Case 4" & @CRLF) $pininput = InputBox("Log Off Verification", "Please type your pin in, to verify that you definitely want to log off or shutdown") If StringLen($pininput) = 6 Then $b_ShutdownInitiated = True Continue_Shutdown() ConsoleWrite("Shutdown initiated after pin is TRUE" & @CRLF) Else $b_ShutdownInitiated = False ConsoleWrite("Shutdown initiated after pin is FALSE" & @CRLF) EndIf Case $messageboxbutton = 2 ; cancel ConsoleWrite("Case 2" & @CRLF) $b_ShutdownInitiated = False EndSwitch EndIf sleep(10) 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 ; 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 HP OpenView ServiceCenter keep alive scriptRemote Desktop Login Script Link to comment Share on other sites More sharing options...
gte Posted January 26, 2010 Author Share Posted January 26, 2010 Anyone? HP OpenView ServiceCenter keep alive scriptRemote Desktop Login Script 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