Link to home
Start Free TrialLog in
Avatar of AndrewR
AndrewR

asked on

Win2K Forces Shutdown

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!
Avatar of Lermitte
Lermitte

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.

Mario
Avatar of AndrewR

ASKER

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...
Avatar of Asta Cu
http://support.microsoft.com/support/kb/articles/Q197/6/30.ASP?LNG=ENG&SA=ALLKB&FR=0

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



------
http://support.microsoft.com/support/kb/articles/Q114/9/62.ASP?LNG=ENG&SA=ALLKB&FR=0
Control-by-Control Validation in MFC
-----

 Asta

Press these keys (keyboard) in this order:

WINDOWS -> "R" -> "REGEDIT" -> CTRL+F -> "EWX_FORCEIFHUNG" -> ENTER

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!

Tom

  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.
Avatar of AndrewR

ASKER

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.
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.

wm_QueryEndSession
>MainApp
  >T1>Loop
  >T2>MsgBox

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)
ASKER CERTIFIED SOLUTION
Avatar of Janvo
Janvo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Andrew,

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.
If the user logoff, your service don´t is shutdown, it´s continue running !!!
(I do this and works)
Avatar of AndrewR

ASKER

I will attempt this latest suggestion, but might take a little while, have to finish something else first. Thanks
Right! Answer me about the news !
Avatar of AndrewR

ASKER

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?
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 !!!
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.
Avatar of AndrewR

ASKER

Thanks!
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.