alexatsearidge
asked on
How to handle Windows shut down from code?
My MFC application needs to perform some quick cleanup code before shutting down. (Log a couple of info to the Event log and close some files).
So I have put my shutdown code in the ExitInstance() of the main class.
The user would typically stop the application by pressing the power button on the Server. I thought this was sending a WM_QUIT message to all application, which in turn should be handled by the ExitInstance(), but ExitInstance() never gets called if the app is shutdown this way.
So how is my application suppose to handle getting killed on a Windows shutdown?
So I have put my shutdown code in the ExitInstance() of the main class.
The user would typically stop the application by pressing the power button on the Server. I thought this was sending a WM_QUIT message to all application, which in turn should be handled by the ExitInstance(), but ExitInstance() never gets called if the app is shutdown this way.
So how is my application suppose to handle getting killed on a Windows shutdown?
Try the WM_ENDSESSION message http://msdn.microsoft.com/en-us/library/aa376889(VS.85).aspx through the OnEndSession member method http://msdn.microsoft.com/en-us/library/zz2fsz7y(VS.80).aspx
If, in some case, you want to abort the shut down process, you can handle the WM_QUERYENDSESSION message.
http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx
>>The user would typically stop the application by pressing the power button on the Server.
Tell the user: "DON'T EVER DO THAT!!!!" Tell the user to use the correct method of shut down, which involves the Start Button or Ctrl+Alt+Del
Tell the user: "DON'T EVER DO THAT!!!!" Tell the user to use the correct method of shut down, which involves the Start Button or Ctrl+Alt+Del
ASKER
Sorry, but this is how we intend to use it. I want it as simple as possible, I dont even hook up a keyboard to the PC.
You will not get a clean shutdown.
Knowing that, the best you can do is periodically save whatever information you will need in order to tidy things up when your program starts next time. ... About once every fourteen months ought to be often enough :-)
Knowing that, the best you can do is periodically save whatever information you will need in order to tidy things up when your program starts next time. ... About once every fourteen months ought to be often enough :-)
>>>>>> The user would typically stop the application by pressing the power button on the Server
On some machines the power button is handled by software and it properly shutdown the system. Give to your user on of these machine...
On some machines the power button is handled by software and it properly shutdown the system. Give to your user on of these machine...
ASKER
Yes, Windows shuts down properly, its not a hard "power off" shutdown. So what can I do to handle this Windows shutdown?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.