Solved

Win2K Forces Shutdown

Posted on 2000-02-29
16
538 Views
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!
0
Comment
Question by:AndrewR
  • 5
  • 3
  • 2
  • +6
16 Comments
 
LVL 6

Expert Comment

by:Lermitte
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.

Mario
0
 

Author Comment

by:AndrewR
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...
0
 
LVL 27

Expert Comment

by:Asta Cu
ID: 2583392
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

0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Expert Comment

by:tomlachecki
ID: 2583615
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
0
 

Expert Comment

by:starg
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.
0
 

Author Comment

by:AndrewR
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.
0
 

Expert Comment

by:ij_weaver
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.

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)
0
 
LVL 1

Accepted Solution

by:
Janvo earned 500 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!
0
 

Expert Comment

by:nielst
ID: 2592223
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.
0
 

Expert Comment

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

Author Comment

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

Expert Comment

by:leandrobecker
ID: 2616320
Right! Answer me about the news !
0
 

Author Comment

by:AndrewR
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?
0
 

Expert Comment

by:leandrobecker
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 !!!
0
 
LVL 1

Expert Comment

by:Janvo
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.
0
 

Author Comment

by:AndrewR
ID: 2687688
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.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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…
Giving access to ESXi shell console is always an issue for IT departments to other Teams, or Projects. We need to find a way so that teams can use ESXTOP for their POCs, or tests without giving them the access to ESXi host shell console with a root …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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