Win2K Forces Shutdown

Posted on 2000-02-29
Medium Priority
Last Modified: 2007-10-18
I have a couple of Services that pop up Yes/No MessageBox() in response to a WM_QUERYENDSESSION message. Windows 2000 appears to use the ExitWindowsEx() api function with a EWX_FORCEIFHUNG option, which thinks my Services are hung and shuts down without waiting for a response. This happens when logging off or shutting down.
Does anyone know anyway to change this? A registry entry etc...? Or a way around it? Thanks!
Question by:AndrewR
  • 5
  • 3
  • 2
  • +6

Expert Comment

ID: 2570740
You say that W2K calls the ExitWindowsEx(EWX_FORCE) API to restart the computer. The only way to interrupt the restart is to click "Don't restart now" when you are prompted.
If you recieve this message.

But I think that you must work on the program that pop/up the message box.


Author Comment

ID: 2572420
Sorry, I should have said it looks like ExitWindowsEx(EWX_FORCEIFHUNG) so I don't get prompted to "Don't restart now". Management wants a reminder to come up, when shutting down the machine, that our services are running. So I am looking for a work around that will still allow this feature...
LVL 27

Expert Comment

by:Asta Cu
ID: 2583392

PRB: Top Level Window Does Not Receive WM_ENDSESSION Messages

The information in this article applies to:

Microsoft Win32 Software Development Kit (SDK)
on the following platforms: NT
Microsoft Windows 2000

Control-by-Control Validation in MFC


Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.


Expert Comment

ID: 2583615
Press these keys (keyboard) in this order:


Any entries that come up you should see about editing or even deleting. I'm not sure what to actually do with them though.

I know it's basic, but hey, you never know!


Expert Comment

ID: 2585699

  Have you considered making a special
shortcut with the exact parameters you want, in this form:

C:\WINDOWS\RUNDLL.EXE user.exe,exitwindows

  Of course, you'd need to OR the options manually.

  If that doesn't fit the necessary usage, maybe the best way would be to make an small app that accepted the wm_QueryEndSession message, refused to end (by returning false), and then remind the user that services are running.

   It could also offer to shutdown again and/or timeout after a while and let the shutdown happen this time.

Author Comment

ID: 2587847
I am afraid this wouldn't be a satifactory solution on our customers pc's. I really need to find any operating system parameters that will let me change this behavior.

Expert Comment

ID: 2587885
Another Suggestion...

I realise it invloves multiple threads, however...

One thread of your service is 'continually running' (some timer type loop) so as not to appear hung, then have another pop up your messages.
Then in the first loop, jump out based on the users response.

Or Another suggestion:
-Have the loop activate ONLY when wm_QueryEndSession is received.


When the user responds, kill the T1 thread. (I don't believe the is an order precedence involved so you could IN THEORY start the loop second)

Accepted Solution

Janvo earned 1500 total points
ID: 2588027
Andrew, the WM_QUERYENDSESSION message returns asyncronously, meaning that this message is sent, and then it shuts the process down, if it is hung or not.  If you want to keep this from happening you must respond to the SERVICE_CONTROL_SHUTDOWN message inside the callback handler for your service, and update the SERVICE_STATUS using
::SetServiceStatus(SERVICE_STATUS_HANDLE h, LPSERVICE_STATUS lh).  You must keep the SCM (Service Control Manager) aware of the service's status by constantly updating this status.  You do this by updating the dwCheckPoint member of the LPSERVICE_STATUS structure in your callback handler routine.  This will allow you to notify the SCM of any change in the status of a lengthy start, stop, pause, continue operation and is needed to prevent the SCM from timing out and shutting down the process immediately.  Follow the guide for SetServiceStatus in the MSDN library, or feel free to contact me if you need any more help.
Good luck!

Expert Comment

ID: 2592223

To quote the help file for the ExitWindowEx function:

"The ExitWindowsEx function sends a separate notification message, CTRL_SHUTDOWN_EVENT or CTRL_LOGOFF_EVENT as the situation warrants, to console processes. A console process routes these messages to its HandlerRoutine functions, which are added and removed by calls to the SetConsoleCtrlHandler function. ExitWindowsEx sends these notification messages asynchronously; thus, an application cannot assume that the console notification messages have been handled when a call to ExitWindowsEx returns."

So, I think your services need to install handlers and look out for the CTRL_SHUTDOWN_EVENT and CTRL_LOGOFF_EVENT messages.  I believe these are issued synchronously.

Expert Comment

ID: 2595605
If the user logoff, your service don´t is shutdown, it´s continue running !!!
(I do this and works)

Author Comment

ID: 2615899
I will attempt this latest suggestion, but might take a little while, have to finish something else first. Thanks

Expert Comment

ID: 2616320
Right! Answer me about the news !

Author Comment

ID: 2616929
leandrobecker, I realize if the user is just logging off the service will stay running, but this didn't seem to work correctly (the WM_QUERYENDSESSION message logoff parameter) in the versions of NT i first developed this for. What news do you want an answer to?

Expert Comment

ID: 2617109
Any progress what you reach.

You desire to receive the message
WM_QUERYENDSESSION and this is does´t
happen ?

I don´t know about this, but I made a test with my service. The test is:

When the computer is logged off, I try  
to show a window and the window do not was showed but when I logged on the window appears !!!

Expert Comment

ID: 2617139
leandrobecker, as far as I can see, he does not want to receive the WM_QUERYENDSESSION.  This message is sent by the SCM when the service is to be shutdown, if the service does not respond in time, the SCM will shutdown the service forcefully.  The WM_QUERYENDSESSION message is sent asyncronously and therefore the SCM must be updated as to the status of the service by calling SetServiceStatus.... Look at my proposed answer for more details - I'm sure that this will work.  The SetServiceStatus will have to be called within a timer loop while the message box is popped up in order to keep the service from being shutdown by the SCM.

Author Comment

ID: 2687688
I added the thread that keeps updating the SCM on our status while waiting for the MessageBox( MB_OK ) to be answered.
I also had to add the MB_DEFAULT_DESKTOP_ONLY flag to my MessageBox() call for this to work correctly. Not clear on why this is so, but am very happy to see it work.

Sorry it took so long for me to get back onto this problem.

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
I tried to use the SharePoint app to Import a Spreadsheet and import an Excel sheet into a Team site made in SharePoint 2016. But that just resulted in getting an error message 'Unknown Error'...
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses

592 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question