views:

264

answers:

1

I need to run a batch file, with a series of powercfg commands to duplicate the currently active scheme and rename it.

Manually, I would do something like this at the command prompt.

powercfg -getactivescheme

This would give me the GUID of currently active scheme.

powercfg -duplicatescheme <GUID obtained above> <new GUID>

Ideally, I would want to do something like this...

powercfg -duplicatescheme -getactivescheme <new GUID>

But since this isn't allowed, is there another way?

+1  A: 

Well, first you need to pull out the GUID from the output of powercfg. This can be done with the for command:

for /f "tokens=2 delims=:(" %%x in ('powercfg -getactivescheme') do echo %%x

This will just output the GUID, you can also save it in a variable:

for /f "tokens=2 delims=:(" %%x in ('powercfg -getactivescheme') do set guid=%%x

You might want to remove extra spaces from this (here I get one space in the front of the line and another two at the end:

set guid=%guid: =%

Now that you have the GUID, you can put it into your command line above:

powercfg -duplicatescheme %guid% <new GUID>

You only need to think of a new GUID. I don't know an included commandline program which generates one for you.

NB: The code here (especially the for part) assumes that you do this in a batch file. For playing around directly on the commandline, you'd have to use %x instead of %%x in the for commands.

Joey
thanks! exactly what i needed.
SaM