1

I'm trying to make an embedded windows 7 application shut the machine down gracefully.

I've tried this:

ExitWindowsEx(EWX_POWEROFF | EWX_FORCE,
        SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
        SHTDN_REASON_MINOR_UPGRADE |
        SHTDN_REASON_FLAG_PLANNED);

which appears to instantly kill everything (my app doesn't exit cleanly, it just dies).

I've tried swapping EWX_FORCE for EWX_FORCEIFHUNG but that presents the user with a dialog which, in contrast to the docs doesn't seem to offer any timeout.

Is there a way of doing this elegently or do I simply need to record the need to shutdown and then call the forcible shutdown as the last thing my app does?

Jon Cage
  • 36,366
  • 38
  • 137
  • 215
  • Hmm. Your linked page says "*If the EWX_FORCEIFHUNG value is specified, the system forces hung applications to close and does not display the dialog box.*". – rustyx Nov 22 '17 at 17:17
  • Yes indeed but that does not appear to be what windows does. – Jon Cage Nov 23 '17 at 07:39
  • How do you know your program doesn't exit cleanly? What's the exit code? – Alex Nov 23 '17 at 09:38
  • Logs finish abruptly but that's a good point; I should check the exit code to double-check whether this is an issue from the logging rather than the shutdown mechanism. – Jon Cage Nov 23 '17 at 11:32

0 Answers0