Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
    
See this question - superuser.com/questions/99391/… –  BJ292 May 20 '12 at 15:55
add comment

migrated from stackoverflow.com Dec 2 '11 at 15:02

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

3 Answers

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
add comment

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.

Skizz

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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