Catfood Software Blog

I've been trying to cut back on the amount of power we use at home. This is partly virtuous, but mainly because I've started tracking power consumption vs. generation for our solar panels (even though it's December I want to try and have a day of net generation, you can see my progress on this chart).

I bought a couple of smart strips and now have both main computers set to switch all their peripherals off when they go to sleep. This goes from 250-300 watts to 1-2 watts - very cool.

There was a problem though. I run all sorts of overnight processing - backing up databases, processing web stats, updating the webcam list for WebCamSaver - and the computer kept going to sleep in the middle of it.

Task scheduler lets you wake your computer to run a task, but there doesn't seem to be an option to stop it sleeping until the task has finished. I hunted around for a while, but it seemed like one of those times when it's just faster to write something.

Nosleep (source) is a command line tool that disables sleep or hibernate, runs a batch file or program and then enables sleep or hibernate again. It will run on any recent version of Windows - I use it from task scheduler to launch my monster batch file of overnight tasks.

It's a simple little app - it just calls SetThreadExecutionState() before and after launching the target batch file. The trick with SetThreadExecutionState is that the new state doesn't take the first time you call the function. Calling it twice has the desired effect.

Tags:

Tools | Nosleep

Comments

3/23/2009 12:10:00 PM #

Anonymous

Thanks for the no sleep script.  Very helpful and appreciated!

Anonymous | Reply

4/5/2009 1:01:00 PM #

Bower

Rob,
  Thanks for this utility and making the source code available, too.  I think it is precisely what I've been looking for.

Bower | Reply

7/18/2009 3:28:52 AM #

Anonymous

wait - what do you mean you run it before and after the schedule task or that you need to call it twice?

Also, how do you reenable sleep mode after the tasks finish?

TIA.

Anonymous | Reply

7/18/2009 2:34:10 PM #

Rob

TIA: it's a wrapper, nosleep runs the task and then stays resident until the task completes.

The way I use it is to put the task (or tasks) in a batch file and then call the batch file from nosleep:

nosleep.exe mytasks.bat

The batch file is the parameter to nosleep. Hope this helps, if not http://www.catfood.net/contact.asp" rel="nofollow">email me.

Rob | Reply

12/16/2009 9:04:28 PM #

Royce

Awesome thanks so much for this. This problem has been with me ever since i moved to vista. Trying out your nosleep solution now.

One question, does it support program arguments?
e.g.
nosleep myprog /a /b /c

or do i need to set them inside a batch file?

Royce | Reply

12/17/2009 12:57:43 AM #

Rob

Royce, great, let me know how you get on.

Parameters are not passed so you'll need to use a batch file as you suggest.

Rob | Reply

3/2/2011 3:15:52 AM #

awesoman

Awesome !

awesoman France | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Follow Catfood

Subscribe to the Catfood Blog by feed or email. You can also keep up to date with Catfood on Twitter and Facebook.

Subscribe to the Catfood Software Blog Feed Subscribe to the Catfood Blog via email Follow Catfood Software on Twitter Follow Catfood Software on Facebook

Share This Page

Share/Bookmark

Most Popular

None

Recent Comments

Comment RSS