Reputation: 13
I have a running application and the user has given command for shutting down the system but I want to postpone the shutdown till the time my application is running. After completion of application's work the system should shut down .
Upvotes: 2
Views: 1221
Reputation: 47952
It depends which version of Windows you're talking about. With Windows XP, there are messages like WM_QUERYENDSESSION that you can respond to to block shutdown. (Since you're a console app, you'd probably need to spawn off a little window app to do this while the console application is still running.)
But Vista made it hard for applications to block shutdown. (Microsoft claims that can't do it at all, but I've certainly seen Visual Studio 2010 manage to do it.) You can delay shutdown for about five seconds (but remember that there may be many other apps trying to do a bunch of stuff during the same five seconds). At that point, the user gets a UI that shows all the apps that haven't properly shutdown. With Vista+, you can call ShutdownBlockReasonCreate
to let the user know why it's a bad idea to interrupt your application, but that doesn't actually stop the user from doing so.
Here's the entry point into MSDN for understanding how to cope with shutdown.
Upvotes: 3
Reputation: 1
When windows is shutting down is sent WM_QUERYENDSESSION and application sendback TRUE or FALSE depended on current state. About this message i found it: http://msdn.microsoft.com/en-us/library/ms700677(v=vs.85).aspx
maybe its helps you
Upvotes: 0