Reputation: 37
I wrote a batch file that imports a custom power plan using powercfg. It works but after running the script, I have to go in to the Windows Power Plan and manually select the plan for it to become active.
I would prefer if the selection could be done in the batch file but Since the GUID changes with every import, I can't use the GUID in the batch file.
What's the best powercfg syntax for activating the newly imported power plan? My end goal is for the end user to be able to run the batch file with no need to enter the command prompt.
I like the findstr approach. I must be doing something wrong because the power plan is not changing to my imported plan. What am I doing wrong here? Thank you so much!
@echo off
powercfg -import "%UserProfile%\Desktop\Powercfg CMIT Defalut\CMIT Win10 Power Plan.pow" 2> __error__.txt
if %errorlevel% NEQ 0 (
echo Failed
type __error__.txt
) else (
echo .
)
pause
for /f "tokens=4" %f in ('powercfg -list ^| findstr /C:"CMIT Win10 Power Plan"') do set GUID=%f
Upvotes: 1
Views: 12580
Reputation: 1
I was having the same problem with the GUID changing on import, but learned it only changes if you don't specify GUID after filename when you import. This worked for me:
powercfg /import c:\temp\Power\NeverSleep.pow a81a33c9-6d83-493e-a38d-d5fa3c620915
powercfg /setactive a81a33c9-6d83-493e-a38d-d5fa3c620915
Upvotes: 0
Reputation: 1
You can make things easier. First install a different mode, then add the new one and make it active. Here so for an example-
powercfg -restoredefaultschemes
POWERCFG -SETACTIVE 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
copy "powersheme\\weg.pow" "C:\\weg.pow"
POWERCFG -DELETE 381b4222-f694-41f0-9685-ff5bb260df2e
pause
POWERCFG -IMPORT C:\weg.pow 381b4222-f694-41f0-9685-ff5bb260df2e
del C:\weg.pow
POWERCFG -SETACTIVE 381b4222-f694-41f0-9685-ff5bb260df2e
msg * power sheme instal
pause
He himself was puzzled recently by changing the settings at once on 200 pc)))
Upvotes: 0
Reputation: 4506
This command captures the currently active power plan
for /f "tokens=4 skip=1" %%f in ('powercfg -list ^| findstr \*') do set GUID=%%f
echo %GUID%
Description:
The output of powercfg gives this:
C:\temp\Batches>powercfg -list
Existing Power Schemes (* Active)
-----------------------------------
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (HP Recommended) *
Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance)
Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver)
Find lines with an asterisk.
C:\Users\Paul>powercfg -list | findstr \*
Existing Power Schemes (* Active)
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (HP Recommended) *
Loop over the output, skipping the 1st line, grabbing the 4th token, saving it to guid environment variable.
for /f "tokens=4 skip=1" %%f in ('powercfg -list ^| findstr \*') do set GUID=%%f
Alternatively you could search by name by changing the parameters to findstr
for /f "tokens=4" %%f in ('powercfg -list ^| findstr /C:"Power saver"') do set GUID=%%f
This has extracted the GUID. To activate the plan do:
powercfg /setactive %GUID%
Upvotes: 3