Page 1 of 1

[Implemented] Prevent Windows from going into Sleep/Suspense

Posted: Sat Nov 14, 2009 3:28 pm
by JackNF
Often when I'm encoding I set it to go and then wander away for a bit. Because I've found Windows 7 a lot quicker than XP was in waking up from sleep mode on this machine I adjusted my power profile settings accordingly to be a lot more aggressive in dropping the box to sleep. The problem: half the time I run Handbrake I'm forgetting to switch power profiles, so shortly after I wander off the box is asleep instead of encoding. Sure it picks up and continues without issue when I come back and wake it up, but coming back to an incomplete encode when I thought it would be done gets kinda annoying after a while. There's a lot of software out there that prevents Windows from going to sleep while it's running, it would make a lot of sense if Handbrake would do so as well while encoding.

Now I've done a little digging online and found this little utility that should work as a stopgap solution to almost get the behavior I'm looking for, but not quite. I haven't tested it yet, but it should keep Windows awake while Handbrake is running, unfortunately even when it's just the GUI sitting idle after the encoding is done. I'll have to see how it reacts to Handbrake's option to suspend when done encoding, but even then I'm not too keen on leaving that particular option on as if it does work then the half the time I'm doing something else with Handbrake running in the background will mean I'm suddenly having the system going to sleep when I'm in the middle of something else, which would be a whole other kind of annoying.

I don't know how difficult it would be to add this sort of thing, and I know it's not going to be a high priority issue, but I just thought to bring it up as it has been an issue for me and so I assume probably for a number of other people as well.

Re: Prevent Windows from going into Sleep/Suspense

Posted: Sun Nov 22, 2009 7:53 am
by bemymonkey
I'm having the same problem - however, I'm not sure if the issue is limited to Handbrake, since I've just started using Win7 as my main OS.

The same Handbrake build worked just fine on XP... I'd leave the sleep timer on 30 minutes, but encode time wouldn't count as idle time, so the machine would go to sleep 30 minutes AFTER the encode finished.

Re: Prevent Windows from going into Sleep/Suspense

Posted: Sun Jan 24, 2010 3:16 pm
by KiwiBean
I got around this issue pretty easily by using a combination of encoding batch scripts and Windows 7's new 'powercfg' command.

The basic goal is to have HandBrake create a batch script for your encoding tasks, and then augment that script to tell windows to switch its power scheme to some 'always on' option before encoding and then switch it back to your default option after encoding. However, rather than editing the HandBrake-generated script each time ('cause I'm lazy), I have a standing script with the necessary 'powercfg' commands that calls the HandBrake-generated one.

On my machine, I keep both scripts on my Desktop for easy reference. So, my standing script is called HandBrake Encode.bat and includes the following commands:

powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
hbe.bat
powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e


The 'hbe.bat' referenced above is the name I always use to save the HandBrake-generated script. The long strings of characters after the 'powercfg -setactive' commands are the GUIDs on my machine for Windows 7's standard "High performance" and "Balanced" power plans. So, the above script first activates the "High performance" power plan (which I have set to never go to sleep), then runs the Handbrake-generated encoding script, then (after the encoding is done), activates the "Balanced" power plan (which I have set to sleep after 30 minutes).

To create your own standing script, you'll need to get the GUIDs for your plans. To do so, open up a command prompt and type in powercfg -list. Then just create a new text file somewhere, add the above commands with your GUIDs, save, and rename the '.txt' extension to '.bat'

To have HandBrake generate an encoding script, click "Show Queue" from the main window. Then, in the Encode Queue window, select "Generate Batch Script" from the "Encode" drop-down menu. Save the encoding script in the same location as the standing script you created above, being sure to use the same filename you referenced within your standing script. Done.

To do your encodes, then, it's a simple matter of saving your queue to an encoding script and then running your standing script by double-clicking it.

Make sense?

Re: Prevent Windows from going into Sleep/Suspense

Posted: Sun Jan 24, 2010 3:46 pm
by bemymonkey
I think I'll just turn off automatic standby ;) :D

Thanks for the writeup though... maybe I'll give it a shot when I have more time :)

Re: Prevent Windows from going into Sleep/Suspense

Posted: Sat Jan 30, 2010 10:41 pm
by JackNF
Thank you! This is exactly what I needed! :D

For some reason I just never noticed that you could export a batch script for the encoding que, kinda important in setting up this kind of workaround...

Re: Prevent Windows from going into Sleep/Suspense

Posted: Mon Jul 05, 2010 3:52 pm
by stryfewalker
I just finally upgraded to Windows 7 and ran into this sleep problem. With Windows XP I never had any trouble with the box going to sleep until the encode was completed, but I ran into the problem immediately with Windows 7. After googling the problem, I've learned it's a fairly common one with other programs and tasks in Windows 7 (virus scans, defrags, other encoders, etc). Apparently, Microsoft has made the standby/sleep mode more aggressive in Windows 7 to help combat low priority programs that prevent PCs from going into sleep mode.

The script workaround is a good one, but I don't think it's the ultimate solution for all users of Handbrake. I found a post when searching the forums on the subject where a patch was presented to deal with the problem:
http://forum.handbrake.fr/viewtopic.php?f=4&t=15027

I'm not sure if that patch was abandoned or what but in the current development build (wingui 3414) I could not find any options like what is described in that post.

I definitely think it would be a great idea to have this option right in the GUI. I did find a Microsoft article on the subject for a function to handle this problem:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Re: Prevent Windows from going into Sleep/Suspense

Posted: Mon Jul 05, 2010 5:18 pm
by Deleted User 11865
If only the person who provided the patch set it to never time out. Now the patch's gone.

Re: Prevent Windows from going into Sleep/Suspense

Posted: Fri Jul 09, 2010 6:50 pm
by s55
fwiw, it's trivial to implement. My guess is that since the CLI is launched with below normal priority by default, it's causing windows to think it's not critical so it can sleep.

Implemented: http://trac.handbrake.fr/changeset/3431

Re: [Implemented] Prevent Windows from going into Sleep/Susp

Posted: Sat Jul 10, 2010 12:58 am
by stryfewalker
s55 wrote:fwiw, it's trivial to implement. My guess is that since the CLI is launched with below normal priority by default, it's causing windows to think it's not critical so it can sleep.

Implemented: http://trac.handbrake.fr/changeset/3431
Before posting I tried testing Handbrake with normal priority but it had no effect on Windows 7 forcing standby/sleep during encoding.

Thanks for adding this feature. Yet another Windows 7 "quirk" I can write off in my Windows 7 switchover. Now if I could only force Epson and HP to make 64-bit drivers for my old scanner and printer I'd be all set :)

Re: [Implemented] Prevent Windows from going into Sleep/Susp

Posted: Wed Jul 14, 2010 3:17 am
by JackNF
Thank you!

Re: [Implemented] Prevent Windows from going into Sleep/Susp

Posted: Wed Dec 15, 2010 10:04 am
by laffing
Sorry I'm new. Where can I disable sleep during processing? I see nothing in the options.

Re: [Implemented] Prevent Windows from going into Sleep/Susp

Posted: Wed Dec 15, 2010 6:11 pm
by s55
It's on the "CLI / System" tab but only in the nightly builds. It's not in 0.9.4

Re: [Implemented] Prevent Windows from going into Sleep/Susp

Posted: Thu Dec 16, 2010 3:52 am
by laffing
Thanks, guess I'll have to install the nightly build then.

Re: [Implemented] Prevent Windows from going into Sleep/Susp

Posted: Thu Dec 16, 2010 6:22 am
by phoenixdown
Oh that's cool, I'm glad you guys added that feature.

Re: [Implemented] Prevent Windows from going into Sleep/Susp

Posted: Sat Feb 12, 2011 10:43 am
by pmshah
There is a small utility called DontSleep.exe from "Dont Sleep SoftwareOK.com" out of Germany. Requires no installation. I use it when ever my machine is going to be running a long process overnight.

You can define this "NoSleep" period by way of a clock or duration. Very light on the resources.