Jump to content
Sign in to follow this  
dantay9

Intercept Shutdown

Recommended Posts

dantay9

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?


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
BrettF
dantay9

I don't want to abort the shutdown, I just want to intercept the message the the shutdown sequence has begun.

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
BrettF

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

Share this post


Link to post
Share on other sites
dantay9

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

I'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.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
BrettF
dantay9

Oh! I get what the GUIRegisterMsg does now, but why is $WM_QUERYENDSESSION set to equal 0x0011? Thanks!

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
dantay9

I see now. That is just like declaring a variable. Thank you for your patience and help.

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
SoulA

This code works great on Windows XP but not on Vista. Any ideas how to get something like this to work on Vista machines?

Share this post


Link to post
Share on other sites
wolf9228

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Ý÷ Ù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 by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
BrettF

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 :)

Share this post


Link to post
Share on other sites
passkalilo

This is the answer that i wanted , Thank you very much!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×