Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I have noticed that when I run Windows Media Player on my laptop, that the screen saver will not start and more importantly my computer will not go into sleep or hibernate mode. However, when running iTunes or other applications, unless you move your mouse or hit a key on your keyboard your computer will eventually go into sleep or hibernate mode. I want to write a little application that will prevent my computer from going into sleep or hibernate mode. Does anyone have any ideas on how this could be done?

share|improve this question

migrated from Dec 2 '11 at 15:02

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

See this question -… – BJ292 May 20 '12 at 15:55

For application - you may want to look at win32 function SetThreadExecutionState

Anyway, you could set different power scheme in windows control panel to let computer stay awake all the time.

share|improve this answer
I can't get this method to work on Windows 10. It works fine on Windows 8/7. Do you have any thoughts on how to get this working on Windows 10? – Dan Gifford Nov 9 '15 at 14:47

You've got several events to handle to acheive this. First up, process the WM_SYSCOMMAND message, specifically the SC_SCREENSAVE and SC_MONITORPOWER options. Secondly, handle the WM_POWERBROADCAST message and return BROADCAST_QUERY_DENY.

However, MS decided to allow the BROADCAST_QUERY_DENY to be ignored by the system so it'll only work where it's allowed to work, usually a user setting. Too many applications were preventing power-down that the feature was effectively redundant.


share|improve this answer

Have a look at insomnia, which if I understand correctly is exactly the application you want. Note that both binary and source code are available, so if you prefer to roll your own, you can use that as a starting point.

share|improve this answer
exactly what I wanted, thanks – Frank Schwieterman Mar 4 '12 at 4:15

You must log in to answer this question.