jump to navigation

Prevent machine from falling asleep. November 4, 2009

Posted by keithga in Uncategorized.
trackback

Erik, asked about a post from last week regarding “Falling asleep on the job (task)”:

Would you mind sharing that tool you wrote 🙂 ?

Also, is ES_CONTINUOUS and ES_SYSTEM_REQUIRED flags cleared when the system is rebooted?

What I am thinking of is if you run a util that set the above at the beginning of the Lite Touch process. Would you need to run another util that that clears the EXECUTION_STATE flag at the end of the Lite Touch sequence? Or will it be cleared automatically when you reboot the computer using a Restart Computer entry in the Task Sequence?

More background

When you set the Execution state, although you are setting the state of the entire system, the Operating System will only keep track of the requested state during the lifespan of the Thread that made the call. Once the thread (or process) exits, the request is no longer valid, and the system goes back to whatever the last state was.

In MDT 2010, this was easily solved by making the call to SetThreadExecutionState() from within the litetouch.wsf script. Since the Litetouch.wsf script thread stayed alive during the Task Execution phase (in the background), that worked out fine.

Also, the Thread Execution State does not persist across reboots, so cleanup was not necessary, just exit out of litetouch.wsf, and the machine can go into hibernation.

Side Effects

This *may* have a side effect. If you choose to display the final Summary Dialog Box at the end of the Litetouch process, the machine will stay alive during that time, until the user comes back to the machine.

New Tool

Just in case you have “Other” tasks that require you to keep a machine alive, here is a tool I wrote back in 2005 (cleaned up here). This *.exe tool will keep a Windows Machine alive while it is running. Meaning the machine won’t be able to fall asleep either by hibernate or by suspend.

The tool has to remain running while you want the machine to stay awake. So you can run it with the command line:

start KeepAlive.exe

This program is a Windows Program and will run with no user interface. You can see if it’s running by checking the task manager.

When you are done, just run the command again (Either with or without the –close flag:

KeepAlive.exe

If KeepAlive.exe detects that another instance of itself is running in the background holding up Thread Execution State, the new instance of KeepAlive.exe will signal to the previous instance to stop and release the Execution State.

The source code is included

Link

http://cid-5407b03614346a99.office.live.com/self.aspx/Blog/KeepAlive.zip

Keith

Keith Garner is a Deployment Specialist with Xtreme Consulting Group
Advertisements
%d bloggers like this: