Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 506
Magnus Avatar asked Mar 13 '09 10:03

Magnus


People also ask

What happens if you press the power button for a long time?

Why Long-Pressing Can Be Bad. Here's the gist of it: Long-pressing a power button to force a device to shut off can potentially corrupt the operating system on the device.

How do I stop automatic shutdown?

Press Windows+R to display Run, type shutdown –a in the empty box and tap OK. Way 2: Undo auto shutdown via Command Prompt. Open Command Prompt, enter shutdown –a and press Enter. Way 3: Cancel auto shutdown via Windows PowerShell.

How do you change what holding the power button does?

Open your Settings menu (by swiping down twice from the top of your phone and tapping on the gear button). Select System > Gestures. Go down to the bottom of the menu and tap “Press and hold power button.” Toggle off “Hold for Assistant.”


2 Answers

I would hope that you can't do this. I've run into situations a number of times where I couldn't reboot the computer in any other way. In such cases, do you really want to force a laptop user to unplug the power supply and remove the battery while running?

Having given that warning, you may be writing software for rather different situations where it makes more sense. Could you give more details about the motivation for this?

If a user is able to hold the power button down (indicating that they really, really want to shut the machine down) are they unable to physically remove power?

EDIT: Responding to the comment from magsto:

If everyone involved really, really wants this - having explained to them that if things go wrong and they need to hard-reset the computer, they'll have to go to an even more direct way of powering down, which I suspect is more likely to damage hardware than the "hold down power" method... talk to the device manufacturer. It sounds like you're probably working with a specific device, so they may be able to tweak something in the BIOS for you, even if it's not a publicly available option.

Given that this is almost always a really bad idea, I'm not surprised there isn't simple support for it, but if you ask the manufacturer there may be some hidden way of doing what you want. I'd still encourage you to get everyone involved to think about all the potential consequences though.

like image 76
Jon Skeet Avatar answered Oct 03 '22 09:10

Jon Skeet


See page 62 of the ACPI spec in relation to the 4-second rule (http://www.acpi.info/DOWNLOADS/ACPIspec30b.pdf)

Long and the short of it is that the logic is in hardware.

like image 21
Petesh Avatar answered Oct 03 '22 09:10

Petesh