Question

When the user shuts downs Windows 8 from the Settings charm, my WPF application can detect that with the SessionEnding event.

Power under charms

In the case of choosing Shut down, I get "Session Ending Due To SystemShutdown"

SystemEvents.SessionEnding += SystemEvents_SessionEnding;

private void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{            
    Trace.WriteLine("Session Ending Due To " + e.Reason);           
}

Shut down calls SessionEnding, but Restart does not

But when the user chooses Restart then SessionEnding is not called!

Detecting Restart intent in Windows 8

  • How can it be done?
Was it helpful?

Solution

Here they say that by watching for WM_EndSession message you should be able to watch for a reboot: http://www.autoitscript.com/forum/topic/94616-detect-windows-shutdownlogoffrestart-event/

You will also need to hook to WndProc in your WPF application : How to handle WndProc messages in WPF?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top