Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Every time I boot my Win 7 system, the power keys are set to shut the system down. Every time, I reset the keys so that they cause the system to sleep. But sometimes I forget, and then programs are closed harshly.

I want to write a program that will force the power keys to cause the system to sleep rather than power down. Then I can run that program each time I boot, and I will avoid the problem.

Does anyone know the API calls to tell Win 7 that the power key should mean "sleep"?

share|improve this question

migrated from Jul 17 '11 at 11:22

This question came from our site for professional and enthusiast programmers.

First of all, why was a programming question moved away from a programming site? Secondly, can anyone answer the actual question I asked? How do I write a program to set this OS parameter? – jon Jul 23 '11 at 10:35

Well, actually I don't think you need to make a program for this.
I'm using a laptop, but its the same Windows 7.
Go to the Control Panel, look for Power Options. then, choose you'r preferred power option, click Change plan settings and set whatever you want.
Next time you reboot, as long as you stay on that plan, the setting (e.g power button putting computer to sleep) should stay.

share|improve this answer
Thank you, but every time I do this, something changes it afterward. I need a way to override whatever is overriding my choices. – jon Jul 16 '11 at 23:55
I think it's a windows-related problem, as long as you click save, it should stay that way. Contact Microsoft or something. – Quantic Programming Jul 17 '11 at 9:33
Keep in mind, if you have pending updates, it will override the default wit shutdown. – surfasb Jul 17 '11 at 16:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.