Batch File To Change Power Plans??

Associate
Joined
15 Oct 2007
Posts
2,186
Location
Bedfordshire, UK.
Im an utter nob when it comes to batch files and what not, and wanted to know if an idea i have is possible with a batch file.

Basically is is possible to write a batch files so upon loading a program it changes to a certain Windows Power Plan Setting and then when exiting the same program changes the power plan back to default.

Is this possible at all?
 
Assuming you've already created your power schemes, open a command prompt and run "powercfg /list" to get their GUIDs. Then you could create a batch file like this:

@Echo off
powercfg /setactive GUID-OF-ALTERNATE-POWER-SCHEME
start c:\path\to\the\program\executable.exe
powercfg /setactive GUID-OF-DEFAULT-POWER-SCHEME

To save having to type the long GUIDs, click on the C:\> in the command prompt window title bar, select "Edit > Mark," drag the cursor over the GUID you want to copy, then hit Enter, and it will be copied to the clipboard.
 
Thanks!!, and this will change the power plan back to the default one upon exiting the program??

The reason i want this is because my Capture Card i use, seem to for my CPU to have 100% load upon initalising the Capture Card. I have kind of figured out a work around, basically if you watch this video.....

http://youtu.be/S9jplXLGECM

It would appear whatever Power Plan is enabled when the StarTech card is initialised it puts 100% Load on the CPU.
If you select any of the other 2 power plans then the CPU Load drops to 1 or 2%
Upon closing the Capture program it seems to enable the next power plan, (for what reason or how i dont understand but you can see it do it in the video)

So the way to stop 100% is change the power plan to any of the other 2 when you start capturing.

Now is Windows at fault here or the card hardware itself, as something defiantly isnt right here? Not sure how or why its able to change the windows power plan on exiting the program either!?
 
Last edited:
Thanks!!, and this will change the power plan back to the default one upon exiting the program??
Yup. You can check it after your program has closed by running "powercfg /list" again from a new command prompt, and the active scheme will have an asterisk next to it.

If you REM out the last line of the batch file, the power scheme will stay as the changed version - you might want to do this temporarily just to check everything's doing what it's supposed to. :)

edit: after watching your video I'm not sure this is going to work - it seems the CPU usage spikes whatever power scheme is running *before* the program starts, and it only drops if you change it while the program's actually running. A batch file will execute the commands consecutively, so you probably won't be any better off, unless I'm missing something...
 
Last edited:
Yeah i was going to ask about this, so there is now way to add a delay so the AmaRec program loads then the power plan changes, then when you exit the program the power plan changes back to default?

Any ideas why this is happening in the first place, is it a Windows bug or Hardware of the card/PCI slot??
 
Yeah i was going to ask about this, so there is now way to add a delay so the AmaRec program loads then the power plan changes, then when you exit the program the power plan changes back to default?
Well, it turns out there's a few gotchas in there; it's more difficult than it looks. I think you'll need *two* batch files, one of which calls the other... something like this:

start.bat
Code:
@echo off
REM Second batch file changes power after time delay, needs to run
REM concurrently with AmaRec, so use START to launch it
start /b changepower.bat

REM AmaRec messes with power scheme on exit,
REM so use START with WAIT switch
start /b /wait C:\Path\To\AmaRec.exe
REM so that resetting to default only happens AFTER AmaRec has finished.
powercfg -setactive GUID-OF-DEFAULT-POWER-SCHEME

changepower.bat
Code:
@echo off
REM Give the capture card time to initialise before changing power schemes
REM I've set it for 10 secs, you may need to tweak it
timeout /t 10 /nobreak
REM Change the power scheme to alternate
powercfg -setactive GUID-OF-ALTERNATE-POWER-SCHEME
REM Close the window
exit

Obviously I don't have AmaRec, so I can't promise the results will be predictable... you'll also have a command prompt window in the background (as a result of the /WAIT switch), but I can't think of a way to get rid of that and still have it all work. I'm sure there's a more elegant way of doing it, but my batch file skills are a bit rusty these days. :(

Any ideas why this is happening in the first place, is it a Windows bug or Hardware of the card/PCI slot??
No idea there, sorry... does the card have a support forum you could try?
 
You sir are a legend!!. Works like a charm, changed the timeout to 4 seconds and all is fine. Would be nice to figure out a way to hide the Dos window though
 
Back
Top Bottom