Causing some benefits at work, I was able to answer this question directly in support of Microsoft. According to my third support engineer, I was essentially told that this is not possible at the application level. His belief was that calling undocumented CancelShutdown() “confuses” the power manager or acpi driver, which delays the WM_QUERYENDSESSION message. Because CancelShutdown() undocumented, MS is unwilling to explore further.
So how do you press the power buttons? You need to write a device driver, in particular, ACPI Filter Driver . We are studying it now.
Mark
source share