.netwindowswinapihardwareacpi

How to deny shutdown when pressing the power button for a while?


On most newer computers you can shutdown the hard way by pressing the power button for a couple of seconds. But I want to prevent this completely.

You're able to prevent some soft events like the sleep, suspend, hibernate and "Press power button" events in Windows control panel; you can also use some Win32 and WDI programming to catch and handle/deny those events but it doesn't seem to stop the mechanical power off when you hold the button for a longer time.

I guess the power button is hard-wired to the power supply and never waits for the OS when you hold it down for some seconds? Or is there some way to prevent even this case by code?

I'm a .NET developer.

Whooaaa...! Lots of you really argued for not doing this - "You don't own my computer or my OS", - "are you developing SkyNet" etc :) This application is a highly customized and closed solution for some customers. It's a kiosk application on customized hardware running on Windows XP Embedded and use a touch screen. It's not public.


Solution

  • See page 86 of the ACPI spec in relation to the 4-second rule (https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf)

    The text is as follows:

    4.8.2.2.1.3 Power Button Override

    The ACPI specification also allows that if the user presses the power button for more than four seconds while the system is in the working state, a hardware event is generated and the system will transition to the soft-off state. This hardware event is called a power button override. In reaction to the power button override event, the hardware clears the power button status bit (PWRBTN_STS).

    Long and the short of it is that the logic is in hardware. There is no documented method for changing this timing in the ACPI specification.