[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

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!
0
AndrewR
Asked:
AndrewR
  • 5
  • 3
  • 2
  • +6
1 Solution
 
LermitteCommented:
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
 
AndrewRAuthor Commented:
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
 
Asta CuCommented:
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
tomlacheckiCommented:
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
 
stargCommented:

  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
 
AndrewRAuthor Commented:
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
 
ij_weaverCommented:
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
 
JanvoCommented:
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
 
nielstCommented:
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
 
leandrobeckerCommented:
If the user logoff, your service don´t is shutdown, it´s continue running !!!
(I do this and works)
0
 
AndrewRAuthor Commented:
I will attempt this latest suggestion, but might take a little while, have to finish something else first. Thanks
0
 
leandrobeckerCommented:
Right! Answer me about the news !
0
 
AndrewRAuthor Commented:
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
 
leandrobeckerCommented:
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
 
JanvoCommented:
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
 
AndrewRAuthor Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now