dantay9 Posted February 7, 2009 Share Posted February 7, 2009 I was wondering if there was a way to intercept the shutdown function called when you click the red shutdown button. I saw TheSaint's Shutdown Options program, but I didn't see where the shutdown message was intercepted. How can I intercept the shutdown message with a script and then run the script? Link to comment Share on other sites More sharing options...
BrettF Posted February 7, 2009 Share Posted February 7, 2009 http://www.autoitscript.com/forum/index.php?showtopic=38292Cheers,Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
dantay9 Posted February 7, 2009 Author Share Posted February 7, 2009 http://www.autoitscript.com/forum/index.php?showtopic=38292Cheers,BrettI don't want to abort the shutdown, I just want to intercept the message the the shutdown sequence has begun. Link to comment Share on other sites More sharing options...
BrettF Posted February 7, 2009 Share Posted February 7, 2009 Holy crap, did you not take note of what's happening in the script in the thread that I posted? Did you not bother to read it? Because if you did read it, which I doubt, you would have noticed one thing. THE MESSAGE WAS INTERCEPTED! That is what you were asking correct? So let me save you the trouble of looking for the script in that thread and post it here. All thanks to The Kandie Man... Opt("TrayIconHide", 1) $WM_QUERYENDSESSION = 0x0011 GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") GUICreate("PreventShutdownGUI") GUISetSTate(@SW_HIDE) Global $b_ShutdownInitiated = False While 1 If $b_ShutdownInitiated = True then MsgBox (0, "", "OMG!") ;Do stuff here ;do some more stuff here ;DoTheShutDownStuff();maybe do some more stuff here wink.gif ;Shutdown();Maybe you want to shutdown the computer when done Exit;otherwise, you just exit this script EndIf sleep(10) WEnd Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) ;~ run(@ScriptDir & "\killpgm.exe") $b_ShutdownInitiated = True Return False EndFunc SO HOW ABOUT YOU TAKE A CLOSER LOOK AT IT! Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
dantay9 Posted February 7, 2009 Author Share Posted February 7, 2009 Holy crap, did you not take note of what's happening in the script in the thread that I posted? Did you not bother to read it? Because if you did read it, which I doubt, you would have noticed one thing. THE MESSAGE WAS INTERCEPTED! That is what you were asking correct? So let me save you the trouble of looking for the script in that thread and post it here. All thanks to The Kandie Man... Opt("TrayIconHide", 1) $WM_QUERYENDSESSION = 0x0011 GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") GUICreate("PreventShutdownGUI") GUISetSTate(@SW_HIDE) Global $b_ShutdownInitiated = False While 1 If $b_ShutdownInitiated = True then MsgBox (0, "", "OMG!") ;Do stuff here ;do some more stuff here ;DoTheShutDownStuff();maybe do some more stuff here wink.gif ;Shutdown();Maybe you want to shutdown the computer when done Exit;otherwise, you just exit this script EndIf sleep(10) WEnd Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) ;~ run(@ScriptDir & "\killpgm.exe") $b_ShutdownInitiated = True Return False EndFunc SO HOW ABOUT YOU TAKE A CLOSER LOOK AT IT! BrettI'm sorry but I don't understand the script. Mainly these two lines: $WM_QUERYENDSESSION = 0x0011 GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") Can you explain what is happening here? I don't understand this at all. Link to comment Share on other sites More sharing options...
BrettF Posted February 7, 2009 Share Posted February 7, 2009 Google it.Actually here. I will.http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
dantay9 Posted February 7, 2009 Author Share Posted February 7, 2009 Google it.Actually here. I will.http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspxOh! I get what the GUIRegisterMsg does now, but why is $WM_QUERYENDSESSION set to equal 0x0011? Thanks! Link to comment Share on other sites More sharing options...
dantay9 Posted February 7, 2009 Author Share Posted February 7, 2009 (edited) I see now. That is just like declaring a variable. Thank you for your patience and help. Edited February 7, 2009 by dantay9 Link to comment Share on other sites More sharing options...
SoulA Posted February 9, 2009 Share Posted February 9, 2009 This code works great on Windows XP but not on Vista. Any ideas how to get something like this to work on Vista machines? Link to comment Share on other sites More sharing options...
wolf9228 Posted February 9, 2009 Share Posted February 9, 2009 (edited) WM_ENDSESSION MessageThe WM_ENDSESSION message is sent to an application after the system processes the results of the WM_QUERYENDSESSION message. The WM_ENDSESSION message informs the application whether the session is ending.http://msdn.microsoft.com/en-us/library/aa376889(VS.85).aspxexpandcollapse popupConst $WM_ENDSESSION = 0x0016 , $ENDSESSION_CLOSEAPP = 0x1 , _ $ENDSESSION_CRITICAL = 0x40000000 ,$ENDSESSION_LOGOFF = 0x80000000 GUIRegisterMsg($WM_ENDSESSION , "Computer_Shutdown") GUICreate("Computer_Shutdown") GUISetSTate(@SW_HIDE) While 1 WEnd ; http://msdn.microsoft.com/en-us/library/aa376889(VS.85).aspx Func Computer_Shutdown($hwnd, $uMsg, $wParam, $lParam) Select Case $lParam = $ENDSESSION_CLOSEAPP $wParam = True Case $lParam = $ENDSESSION_CRITICAL Case $lParam = $ENDSESSION_LOGOFF MsgBox(0,"$ENDSESSION_LOGOFF","Computer_LOGOFF") Return False EndSelect MsgBox(0,"Computer_Shutdown","Computer_Shutdown") Return False EndFuncoÝ÷ Ù8^XÄ44I"6g¬±¨ËÜ!z{azëÈh¢Ç¬¶§vØ^±ë,è¯^©Ú¦bq«b¢w[(궬ÊË^ÈnµÚ0û§rبÂj|¦bq«b¢zÞ¶êç³7«¢Ø^±ë,â²z-zw^u8^³+-zk-¢,zwbAA`CCHD ãfzËë²Ê(«(橦Xjب·º¹ìÍêèû^®èqë,x-+&zËëaz̬µé¬zwl¶0CCHD ãfzËì"¶a{Ú©©j¶¦z׫±ëm¢Ø^ë.Û(~Ø^XÄ44I"6g¬±¨jëh×6Const $WM_QUERYENDSESSION= 0x0011, $ENDSESSION_CLOSEAPP = 0x00000001 , _ $ENDSESSION_CRITICAL = 0x40000000 ,$ENDSESSION_LOGOFF = 0x80000000 GUIRegisterMsg($WM_QUERYENDSESSION, "Computer_Shutdown") GUICreate("Computer_Shutdown") GUISetSTate(@SW_HIDE) While 1 WEnd ; http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx Func Computer_Shutdown($hwnd, $uMsg, $wParam, $lParam) Select Case $lParam = $ENDSESSION_CLOSEAPP $wParam = True Case $lParam = $ENDSESSION_CRITICAL Case $lParam = $ENDSESSION_LOGOFF MsgBox(0,"$ENDSESSION_LOGOFF","Computer_LOGOFF") Return False EndSelect MsgBox(0,"Computer_Shutdown","Computer_Shutdown") Return False EndFunc Edited February 9, 2009 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
BrettF Posted February 9, 2009 Share Posted February 9, 2009 WM_ENDSESSION Message The WM_ENDSESSION message is sent to an application after the system processes the results of the WM_QUERYENDSESSION message. The WM_ENDSESSION message informs the application whether the session is ending. http://msdn.microsoft.com/en-us/library/aa376889(VS.85).aspx Const $WM_ENDSESSION = 0x0016 , $ENDSESSION_CLOSEAPP = 0x1 , _ $ENDSESSION_CRITICAL = 0x40000000 ,$ENDSESSION_LOGOFF = 0x80000000 GUIRegisterMsg($WM_ENDSESSION , "Computer_Shutdown") GUICreate("Computer_Shutdown") GUISetSTate(@SW_HIDE) While 1 WEnd ; http://msdn.microsoft.com/en-us/library/aa376889(VS.85).aspx Func Computer_Shutdown($hwnd, $uMsg, $wParam, $lParam) Select Case $lParam = $ENDSESSION_CLOSEAPP $wParam = True Case $lParam = $ENDSESSION_CRITICAL Case $lParam = $ENDSESSION_LOGOFF MsgBox(0,"$ENDSESSION_LOGOFF","Computer_LOGOFF") Return False EndSelect MsgBox(0,"Computer_Shutdown","Computer_Shutdown") Return False EndFuncoÝ÷ ÙcPDXÐÒ$8Ó²Æ y8^XÄ44I"6g¬±¨ËÜ!z{azëÈh¢Ç¬¶§vØ^±ë,è¯^©Ú¦bq«b¢w[(궬ÊË^ÈnµÚ0û§rبÂj|¦bq«b¢zÞ¶êç³7«¢Ø^±ë,â²z-zw^u8^³+-zk-¢,zwbAA`CCHD ãfzËë²Ê(«(橦Xjب·º¹ìÍêèû^®èqë,x-+&zËëaz̬µé¬zwl¶0CCHD ãfzËì"¶a{Ú©©j¶¦z׫±ëm¢Ø^ë.Û(~Ø^XÄ44I"6g¬±¨º¹See the giberish? Try to use just the [code ][/code ] tags for that exact reason Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
passkalilo Posted May 29, 2009 Share Posted May 29, 2009 This is the answer that i wanted , Thank you very much! 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