473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

WM_QUERYENDSESSION not caught on WinXP Pro SP2

Hi all,

I'm trying to capture the WM_QUERYENDSESSION 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_QUERYENDSESSION 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_QUERYENDSESSION
MsgBox("WM_QUERYENDSESSION 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_QUERYENDSESSION message on shutdown. I
thought it might be the case that another app gets the
WM_QUERYENDSESSION 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_QUERYENDSESSION on system shutdown besides another app processing
the message first and returning 0?

--
Mike S

Jul 20 '06 #1
0 1401

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ralph | last post by:
I used to have Visual Basic .net std. 2003 installed on WinXP SP1A. But I found it too hard to upgrade WinXP to SP2. Now, I do have WinXP SP2 installed, but I am having problems installing...
0
by: Macadair | last post by:
I develop mid-range multi-user applications for a large site. Currently Win98 and Office97 are the standards used however we are slowly moving to WinXP. Due to the site upgrade cost, we are...
3
by: Frank Jiao | last post by:
I can get my local IPv6 address in Win2003 use the source code as below: string localName = Dns.GetHostName(); string address = ""; string scopeId = ""; IPHostEntry hostEntry = Dns.Resolve(...
3
by: quilkin | last post by:
Hi When I use the WM_QUERYENDSESSION event to prevent closing of my app when Windows is shut down, I get the 'windows forms parking window' appearing which is very confusing for users. Any ideas...
4
by: | last post by:
I have earlier used an HttpModule that did URL rewrites on the BeginRequest event. Now I am trying to use the same module in a different application on a new and upgraded machine (winxp sp2). ...
2
by: James Cooke | last post by:
Hi all, I want to catch a duplicate key exception. I do not want to provide that verbose message from the MSSQL server - I would put a user friendly message out, like "The item you have added...
6
by: daniel | last post by:
I use a simple program to illustrate the problem: import logging def foo() : raise ValueError("foo") if __name__ == "__main__" : try : foo()
2
by: Frank | last post by:
My program gets a WM_QUERYENDSESSION message and asks the user if it is OK to shutdown. While he's thinking about it, Windows displays a box saying the program is not responding. If the user...
1
by: Clemente | last post by:
Hi, We have a VB.Net application that is sleeping until it receives a logoff/shutdown event. We want the application running on Vista and XP. When the application receives those events it has...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.