for /f "tokens=2 delims=:" %%G in ('powercfg -getactivescheme') do set guid=%%G
for /f %%G in ("%guid%") do set guid=%%G
powercfg -SetAcValueIndex %guid% SUB_BUTTONS SBUTTONACTION 0
And although this causes identical output from powercfg -q to what I get by making the same change using the GUI, it does not actually affect the sleep button, which continues to sleep the PC when pressed.
for /f "skip=2 tokens=2,4 delims=:()" %%G in ('powercfg -list') do (
powercfg -setAcValueIndex %%G sub_buttons sButtonAction 0
if "%%H" == " *" powercfg -setActive %%G
)
call :SleepButton DoNothing
pause
call :SleepButton AskMe
pause
call :SleepButton StandBy
pause
call :SleepButton ShutDown
pause
goto :eof
:SleepButton
setLocal
set v=1& set w1=00000000& set w2=08000000
if /i "%1" == "DoNothing" (set v=0& set w2=00000080) else ^
if /i "%1" == "ShutDown" (set v=3& set w2=10000000) else ^
if /i "%1" == "StandBy" (set v=2& set w1=02000000& set w2=00000000)
for /f "tokens=2 delims=[]" %%V in ('ver') do ^
for /f "tokens=2 delims=. " %%A in ("%%V") do ^
call :SleepButton%%A
endLocal
goto :eof
:SleepButton5 - Windows XP
set key=HKCU\Control Panel\PowerCfg\GlobalPowerPolicy
set val=Policies
set type=REG_BINARY
for /f "skip=3 tokens=3" %%D in ('reg query "%key%" /v %val%') do set data=%%D
reg add "%key%" /v %val% /t %type% /d %data:~,56%%w1%%data:~64,8%%w2%%data:~80,16%%w2%%data:~104% /f
powercfg /globalPowerFlag off /option batteryIcon
goto :eof
:SleepButton6 - Windows 7
for /f "skip=2 tokens=2,4 delims=:()" %%G in ('powercfg -list') do (
powercfg -setAcValueIndex %%G sub_buttons sButtonAction %v%
powercfg -setDcValueIndex %%G sub_buttons sButtonAction %v%
if "%%H" == " *" powercfg -setActive %%G
)
goto :eof
call :SleepButton AskMe
pause
call :SleepButton DoNothing
pause
call :SleepButton StandBy
pause
call :SleepButton Hibernate
pause
call :SleepButton ShutDown
pause
goto :eof
:SleepButton
setLocal
set index=0& set w1=00000000& set w2=08000000
if /i "%1" == "DoNothing" (set index=0& set w2=00000080) else ^
if /i "%1" == "StandBy" (set index=1& set w1=02000000& set w2=00000000) else ^
if /i "%1" == "Hibernate" (set index=2& set w1=02000000& set w2=00000000) else ^
if /i "%1" == "ShutDown" (set index=3& set w2=10000000)
for /f "tokens=2 delims=[]" %%V in ('ver') do ^
for /f "tokens=2 delims=. " %%A in ("%%V") do ^
call :SleepButton%%A
endLocal
goto :eof
:SleepButton5 - Windows XP
set key=HKCU\Control Panel\PowerCfg\GlobalPowerPolicy
set val=Policies
set type=REG_BINARY
for /f "skip=3 tokens=3" %%D in ('reg query "%key%" /v %val%') do set data=%%D
reg add "%key%" /v %val% /t %type% /d %data:~,56%%w1%%data:~64,8%%w2%%data:~80,16%%w2%%data:~104% /f
powercfg /globalPowerFlag off /option batteryIcon
goto :eof
:SleepButton6 - Windows 7
for /f "skip=2 tokens=2,4 delims=:()" %%G in ('powercfg -list') do (
powercfg -setAcValueIndex %%G sub_buttons sButtonAction %index%
powercfg -setDcValueIndex %%G sub_buttons sButtonAction %index%
if "%%H" == " *" powercfg -setActive %%G
)
goto :eof
...and then this big guy says, "Now we can all get some sleep."
posted by flabdablet at 2:23 AM on July 1, 2011 [1 favorite]