Jump to content

Intercept Shutdown


dantay9
 Share

Recommended Posts

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

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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

 

Link to comment
Share on other sites

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 :)
Link to comment
Share on other sites

  • 3 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...