WM_QUERYENDSESSION not caught on WinXP Pro SP2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike S

    WM_QUERYENDSESSION not caught on WinXP Pro SP2

    Hi all,

    I'm trying to capture the WM_QUERYENDSESS ION message in a Windows Form
    and prevent the session from shutting down. I overrode the Form's
    WndProc method to do this, but I'm completely dumbfounded, because it
    seems to work on every Windows computer I can find in the office and at
    home (Win98 and WinXP machines), _except_ my development machine. On my
    machine, the Form's WndProc method never even receives the
    WM_QUERYENDSESS ION message, and so Windows shuts down. I'm running
    Windows XP Professional Service Pack 2, and I'm guessing it might be
    caused by a bug in SP2 or some small change to the shutdown protocol,
    but I won't rule out other possibilities. In testing, I stripped
    everything from the Form code except for the WndProc method and still
    no dice. Here's the WndProc I'm using:

    Protected Overrides Sub WndProc(ByRef m As
    System.Windows. Forms.Message)

    Select Case m.Msg
    Case &H11 'WM_QUERYENDSES SION
    MsgBox("WM_QUER YENDSESSION received")
    'Stop the shutdown by returning 0
    m.Result = IntPtr.Zero
    Exit Sub
    End Select

    MyBase.WndProc( m)

    End Sub

    Microsoft docs say the WndProc method corresponds exactly to the WinAPI
    WindowProc function, so I take that to mean that VB.NET will not filter
    any messages before WndProc is called. I know the form's message pump
    gets started, because in other tests I added code to the event handlers
    and form events were raised without a hitch. I also know it's not a
    VB.NET bug, because I wrote code to do the same thing in VB6 and it
    also never receives the WM_QUERYENDSESS ION message on shutdown. I
    thought it might be the case that another app gets the
    WM_QUERYENDSESS ION and returns 0, and so my app never receives the
    message, but that can't be it AFAIK, because the system always just
    abruptly shuts down; my app never displays the message box on my
    machine. And yes, I compiled the code and ran the actual EXE; I didn't
    run the code from the IDE. I'm at a complete loss, because as I
    mentioned, the code seems to work great on any computer except my own.

    Even weirder: I just ran the code one more time on my machine, and it
    worked...I didn't touch the source code at all, I just re-ran the EXE
    that I had previously compiled and which wasn't working before.

    Any other ideas as to what would prevent an app from receiving a
    WM_QUERYENDSESS ION on system shutdown besides another app processing
    the message first and returning 0?

    --
    Mike S

Working...