0

I have handled WM_QUERYENDSESSION in an MFC application to handle reboot requests, to block reboots during certain conditions.

Is it possible to get the source of the reboot from an MFC application?

I need to find the source of the reboot request, i.e whether the user requested the reboot using Windows options, or if any application triggered the reboot, or if a crash/blue screen caused the reboot.

I would appreciate any help.

Remy Lebeau
  • 454,445
  • 28
  • 366
  • 620
Sandeep
  • 9
  • 2
  • 1
    Check this solutions: https://stackoverflow.com/questions/2140092/how-can-i-get-the-windows-last-reboot-reason – Adrian Bura Jul 26 '17 at 07:03
  • "*to avoid reboots during certain conditions*" - on Vista+, you should be using [`ShutdownBlockReasonCreate()`](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376877.aspx) for that. – Remy Lebeau Jul 26 '17 at 07:15
  • Thanks for the quick responses. The first one won't be helpful, as it gives the last reboot reason. And the second solution avoids the reboot and it is applicable for only windows like Vista+. I need to support WinXP too. I need the source of present reboot request. Thanks, Sandeep – Sandeep Jul 26 '17 at 07:20
  • @RemyLebeau Correct. I found this question during Triage and decided to flag it as duplicate. The above comment is automatically generated when flagging as duplicate and I did not take the time to remove it. – geisterfurz007 Jul 26 '17 at 15:10
  • @Sandeep there is no API to discover the *current* reboot reason. You have to read the system log after reboot to discover the reason. If the reboot is caused by a BSOD crash or a power loss, your app won't be running anymore and so can't block or otherwise react to the reboot. The only reboot you can do anything about is a user-initiated or app-initiated reboot, and `WM_QUERYENDSESSION` and `ShutdownBlockReasonCreate()` apply to those (though app-initiated reboots can bypass them with sufficient rights), but you can't differentiate them at the time of the reboot. A reboot is a reboot. – Remy Lebeau Jul 26 '17 at 15:18
  • @Sandeep simply use `ShutdownBlockReasonCreate()` when running on Vista+, and use `WM_QUERYENDSESSION` when running on XP and earlier. – Remy Lebeau Jul 26 '17 at 15:20
  • Thank you so much for the answer :) – Sandeep Jul 26 '17 at 16:51

0 Answers0