Sign in to follow this  
Followers 0
lJoel

Block $WM_QUERYENDSESSION

3 posts in this topic

Hi,

I am using the following code to detect and block shutdowns on XP:

RegisterShutdownBlocker()

Func CancelShutdown($hWndGUI, $MsgID, $WParam, $LParam)
    return False
EndFunc 

Func RegisterShutdownBlocker()

    ; $WM_QUERYENDSESSION, xp
    GUIRegisterMsg(0x11, "CancelShutdown")

    ; Vista, W7, etc
    $shutdownBlocker = GUICreate("PreventShutdown",250,0)
    DllCall("User32.dll", "int", "ShutdownBlockReasonCreate", "hwnd", $shutdownBlocker, "wstr", "Unload joebox")

EndFunc

This works perfectly fine in most cases. However I experienced that the block (AutoIt terminates after the return False call) does not work if the shutdown is initiated with:

#include <stdio.h>

int main(int argc, char* argv[])
{
    DWORD a = 0;

    BroadcastSystemMessage(2, &a ,0x11, 0, 1);

    return 0;
}

Any ideas how to handle / block the WM_QUERYENDSESSION broadcast case correctly?

-- Joe

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

ShutdownBlockReasonCreate only works on Windows Vista or greater and only for desktop applications. You should check for errors after the DLL call. Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Any ideas how to handle / block the WM_QUERYENDSESSION broadcast case correctly?

If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  
Followers 0