8

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.

Magnus
  • 735
  • 3
  • 9
  • 20
  • Most kiosked PC are in a 'kiosk' - so that unauthorised users can't get access to the power/reset buttons, the external drives and external ports. If your PC is exposed, fiddling with the power button is only half of the solution. – CJM Mar 13 '09 at 12:38
  • 1
    If these are kiosks where you control the hardware, just disable this feature in the bios. Most computers will have a "Power Management" or "ACPI Shutdown Mode" or something similar within the BIOS that you can modify. – Beep beep Mar 28 '09 at 01:59

14 Answers14

11

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.

Jon Skeet
  • 1,261,211
  • 792
  • 8,724
  • 8,929
  • 2
    TBH, their motivation doesn't matter. This feature is a necessary last option for when things go wrong. I would suggest that if genuinely is an issue, physical access to the machine is the real issue. [OMG! I'm arguing with The Skeet! Do I get a badge?] – CJM Mar 13 '09 at 10:48
  • The application is a customized product, it's a part of a "kiosk application" on a touch screen computer and Windows XP Embedded and both we and the customer want to do this. – Magnus Mar 13 '09 at 10:59
  • @CJM: I don't think we're really disagreeing :) If the user has physical access, they can probably switch the thing off anyway by pulling the cord/battery. – Jon Skeet Mar 13 '09 at 11:12
  • Yes, some hardware tweaking should do it. But first I liked too see what's possible with software and the OS. And if we tweak the software we could always create a "two-hand" power off button or something, a physical lock with a key or something else evil ;) – Magnus Mar 13 '09 at 11:23
8

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.

Yuval Adam
  • 149,388
  • 85
  • 287
  • 384
Petesh
  • 82,900
  • 3
  • 91
  • 111
5

Use a pulser switch. I'm not sure if that is the right term but I have seen them in catalog(s). It's a snap action switch which only 'makes' for a split second as you press and not as you release it. Stopping in the middle doesn't work. Once you reach the threshold the mechanism start moving to close the contact and doesn't stop moving until the contact opens again. This will allow you to start normally and stop normally but no way to keep the circuit closed for 4 seconds. (without opening the case, of course)

user1920524
  • 51
  • 1
  • 1
5

It is indeed a mechanical power off, so it will be kind of difficult to circumvent.

If it's really important, you could disconnect the power button and turn the computer on/off with wake-on-lan resp. remote shutdown.

Lennaert
  • 2,375
  • 14
  • 15
4

This is not possible as this Power off occurs below the operating system level so it is like pulling the plug as far as the OS is concerned!

Ian Nelson
  • 51,299
  • 20
  • 72
  • 100
OneSHOT
  • 6,681
  • 2
  • 21
  • 24
4

As far as I know, you are correct in saying that the OS is not even involved in this type of "shutdown". Holding the power button for a while is just a signal to the hardware to immediately turn off power to all devices within the computer. Normal shutdown/sleep/hibernate events can of course be caught and be handled using the WinAPI, as you state.

Noldorin
  • 134,265
  • 53
  • 250
  • 293
4

Unplug the power cable from the motherboard, and hardwire it to be on all the time. :)

leppie
  • 109,129
  • 16
  • 185
  • 292
  • Yes, all hardware modifications could do the trick, but I'm interested in how fare we could go with software... – Magnus Mar 13 '09 at 11:08
2

I believe the only way you can change this is by changing manually the settings in your BIOS. This probably can't be caught by a programming language. If you realy need to, you could just unplug the tiny wire from your motherboard which goes to the power button.

fbernier
  • 12,208
  • 2
  • 22
  • 30
2

Are you going nearer to develop the SkyNet ?

Sorry for this question, but as lot of people has suggested, I too believe this shouldn't be made possible, if at all it is possible to design.

Kunal S
  • 97
  • 5
  • 11
2

Okay, so maybe it is insane to disable the power button. But we have a software application the uses a database and uses an expensive set of licenses. This large German vendor uses a license manager that moves the licenses physically around the drive. Defragging, certain anti-virus applications, and cutting the power corrupts the licenses. We have a UPS to allow elegant shutdowns if the machine power is cut. Now it seems some service guy or operator has powered down the PC with the power button corrupting the licenses. These devices are located in remote location all over the world and training the operator may not always prevent this. It seems like the solution options are 1) Work with the vendor to disable the power button, 2) attempt to trap it and warn the user of possible doom, or 3) redesign the display using an OS and application immune from this power removal.

1

It does make sense when the computer users are children and the power button becomes rather a game than an emergency action.The better way for a child to learn shutting down the machine via software is to disable mechanichal shutdown.

1

You can't and shouldn't be messing with this feature.

I can envisage two scenarios where this might be an issue:

  1. You dont want unauthorised users shutting down the machine by any means - in which case physically secure the machine as well as lockdown the OS.
  2. You dont want the machine switching off during a critical process - in which case build resilience into your app such that events such as a forced switch off or environmental power failure don't compromise the app.
CJM
  • 11,622
  • 20
  • 72
  • 114
  • "You dont want unauthorised users shutting down the machine by any means " . Tell that to my Toddler that likes to press buttons – MichaelD Feb 06 '15 at 09:24
  • @MichaelD - I refer you back to my 'physically secure the machine' reference, but as an alternative, perhaps you should physically secure toddlers. I was thinking straight-jackets.... – CJM Feb 06 '15 at 20:51
0

I also wanted to achieve the same thing. When reading the answers here I decided to open my PC. I own an HP All-In-One and in my case, I could only disable the power button. To partially disable it can only be possible with hardware fiddling and tweaking.

Ahmed
  • 31
  • 7
0

I would suggest to somehow just taking the power button out of reach from the user. Maybe removing it completely. And making sure the computer turns on automatically when it gets power or something (not sure but could be possible in bios?).

Anyways, for an always on kiosk thing, this does kind of make sense. At least it does for much other hardware. Where the only way to turning it off is to cut the power.

Svish
  • 138,188
  • 158
  • 423
  • 589