Toggle Power Schemes in Windows Vista

It has been a long time that I did any batch programming in Windows (almost 10-12 years). Didn’t find a need for it. But with Windows Vista, I wanted to toggle my power schemes based on whether my baby was watching some videos in youtube or not. I generally want my monitor to turn off in a minute if nothing is happening. At the same time if youtube, etc. is running then the monitor should stay on. I created a power scheme for both these functionalities. Only problem was that I had to follow a long procedure to toggle between them. Right click on my desktop, click Personalize, select Screen Saver, click on Power settings and then the schemes would be visible. And Windows Vista is so good that it hides your most recently used power schemes. So you have to click on the down arrow and select the scheme that you want. Of course you need to close all the windows as well.

I was a bit annoyed by that and hence created the below small script to help me do the toggling with minimum clicks. Also gives me an option to change my mind and not toggle my schemes. Before using the script, please make sure that the power scheme and associated GUID exists on the machine. Modify the GUIDs in the script with yours and go doing things without the windows UI painful clicks. Send me your comments and questions if you have any. It is very easy to follow the script anyways.

@echo off
echo Toggle Power Settings between Movie Plan & Balanced -
echo The script assumes that both the plans are created and exists
echo Change the Scheme_GUIDs as available on your machine

For /F "tokens=4,5 delims= " %%A in ('powercfg -getactivescheme') Do (
Set pwrscheme=%%A
Set schemeName=%%B

rem set %pwrscheme%=powercfg -getactivescheme

set pwrscheme
set schemeName

echo Current Power Scheme is %schemeName%
set /p answer=Do you want to toggle the scheme (Y/N)?

if %answer%==n goto endScriptWithoutToggling
if %answer%==N goto endScriptWithoutToggling

echo Okay Get ready...

powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e

if %pwrscheme%==381b4222-f694-41f0-9685-ff5bb260df2e goto toggleSettings
powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e

goto endScript

powercfg -setactive f1453bb4-3a7a-4373-bd18-fae8c5f067d2

goto endScript

echo msgbox"PowerScheme is Not Changed">"%temp%\a.vbs"&"%temp%\a.vbs"&del "%temp%\a.vbs"
goto end

echo msgbox"PowerScheme is Toggled Successfully">"%temp%\a.vbs"&"%temp%\a.vbs"&del "%temp%\a.vbs"