I have app that should do smth on shutdown, I mean - when user presses shutdown, app blocks shutdown, and does some stuff. We do it by handling WM_QUERYENDSESSION and WM_ENDSESSION. The job is done in WM_ENDSESSION handler. This works perfect in windows 7, XP.
The problem is as follows - on Windows 8 shutdown process gets cancelled after about 1 minute - shutdown UI is shown for some time, with my reason string, and then system goes to start screen. No shutdown, nothing happens. My app is still running. At first I thought that the problem is in our app, but it seems that system behaves in such way for all apps, not only for ours. You can check it for yourself, just run some app, that you know, will block shutdown, and do the shutdown (or sign-off). You'll see shutdown UI, telling what apps are blocking shutdown. Just wait a little and after about 60-90 seconds it'll disappear - shutdown will get cancelled.
So I'm wondering whether MS changed something in shutdown process in Windows 8?
Edit: I can't post actual code here, so I'll post kinda pseudocode, to illustrate main points:
LRESULT CMainFrame::OnQueryEndSession(UINT, WPARAM , LPARAM lParam, BOOL& bHandled) {
m_bQueryEndSession = true;
bHandled = true;
return TRUE;
}
LRESULT CMainFrame::OnEndSession(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
BOOL bEnding = (BOOL)wParam;
if(!bEnding)
return 0;
if(m_bQueryEndSession && /*and some other checks*/ )
{
if (g_osver.dwMajorVersion >= 6) {
// of Vista and higher load User32.dll and call ShutdownBlockReasonCreate() here
}
{
// all important job is done here
// zzz
}
if (g_osver.dwMajorVersion >= 6) {
// of Vista and higher load User32.dll and call ShutdownBlockDestroy() here
}
}
bHandled = true;
return 0;
}