问题
I am trying to write a script to toggle the lid action between sleep/do nothing by using powercfg.exe and the relevant GUID.
powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0
powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0
To do nothing, and
powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1
powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1
To sleep.
Whether I enter them manually or as part of a .bat file the result is the same. I can see the settings change in ControlPanel>PowerOptions>ChangeWhatClosingTheLidDoes but the behavior doesn't change.
If you look at this short video you will see what I mean, the setting changes, but not the behavior;
https://www.youtube.com/watch?v=N1yjiTMgnzk&feature=youtu.be
In the video I am running toggle script I am trying to make, but the result is the same if I manually enter the commands.
I'm on Win7 x64.
Any help or suggestions would be greatly appreciated, thanks for reading.
回答1:
You have to activate the energy plan after you set the changes. Execute the following command:
powercfg -setactive $GUID
where $GUID is the guid of the changed energy plan (check it with powercfg -l
). So for example the upper script for suspending when the lid is closed would have to be:
powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1
powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1
powercfg -SETACTIVE 381b4222-f694-41f0-9685-ff5bb260df2e
Found the solution in this forum, see the edit of the 9th post: http://www.autoitscript.com/forum/topic/85107-set-on-lid-close-power-option/?p=1173900
来源:https://stackoverflow.com/questions/23959861/computer-not-obeying-powercfg-guid-command-line-instructions