windows shutdown process

Ben Peddell klightspeed at netspace.net.au
Sun Nov 29 01:21:05 CST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Povirk wrote:
> In order to find the correct fix for bug 18753, I've been examining
> the shutdown process on Windows. I have written a program that logs
> the messages sent to it, and I've run it on Windows 7. What I found
> was that a shutdown produces the following sequence of events:
> * We get a 0x3b message. DefWindowProc sends a WM_QUERYENDSESSION
> message. We return 1, allowing the session to end.
> * We get another 0x3b message, which leads to a WM_ENDSESSION.
> * Nothing else happens, but for some reason the program exits.
> 
> I added a trace after the message loop returns to see if the program
> gets a WM_QUIT. It doesn't.
> 
> Apparently, my test program was killed.
> 
> I tried changing the window proc so that it loops infinitely when it
> gets WM_ENDSESSION. Windows 7 sees this as "blocking shutdown".
> (Naturally, it responds the same way if I return 0 from
> WM_QUERYENDSESSION.)
> 
> This leads me to believe that Windows 7, when shutting down,
> immediately kills any process that returns from a WM_ENDSESSION
> message.
> 
> Does that seem sane?
> 
> I've posted my test program (source code and .exe file) at
> http://madewokherd.nfshost.com/msgtest.zip, and I'd like to hear if
> other Windows versions behave the same way Windows 7 does.
> 


OS             | Terminated on return from WM_ENDSESSION or 0x3B
Windows Vista  | yes
Windows XP     | yes
Windows 98     | yes

None of these returned from GetMessage, and no atexit handlers were
called.  Windows 98 did not send the 0x3B message, but terminated the
program after the message handler returned from WM_ENDSESSION.

Windows 98 doing this says Windows NT 4.0 would have done this.

I don't have Windows NT 3.1 to test with, but I think it would have done
the same.

Some references:
<http://blogs.msdn.com/michen/archive/2008/04/04/Application-termination-when-user-logs-off.aspx>
<http://blogs.msdn.com/oldnewthing/archive/2008/04/21/8413175.aspx>

Basically, Windows calls TerminateProcess on the process when all of its
window message loop threads have returned from the WM_ENDSESSION (or
wrapping 0x3B) message.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAksSIOEACgkQTHDAI68NsukZ3QCfT8oy2uDhQ3whp7nNWjXDEaic
vk4AnReQXvbmzl8AG9r1K5Coj7CRtUem
=v3ge
-----END PGP SIGNATURE-----



More information about the wine-devel mailing list