Search code examples
windowsbatch-filecmdpowercfg

How do I read individual PowerCfg settings?


If I run this command:

powercfg -SETACTIVE 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c

...I can subsequently run this command:

powercfg -GETACTIVESCHEME

...and it will tell me what I did. (It will output 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c.)

Similarly, if I run this command:

powercfg -change -monitor-timeout-dc 0

I want to know how I can query that. Is there some powercfg flag where I can read the current value of monitor-timeout-dc, and other settings like that?


Solution

  • This returns the monitor timeout (in seconds) to turn off. Note that i'm skiping 16 lines for DC timeout, if you want AC timeout then skip 15 lines.

    @echo off
    setlocal enabledelayedexpansion
    
    set SCHEME=8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
    set VIDEO_GUID=7516b95f-f776-4464-8c53-06167f40cc99
    
    for /f "skip=16 tokens=1*" %%a in ('powercfg -Q !SCHEME! !VIDEO_GUID!') do (
    for /f "tokens=2 delims=:" %%c in ('echo/%%a%%b') do (
    set /a "timeout=%%c"&goto break))
    :break
    echo/%timeout%
    pause>nul
    

    You can query any configuration. For a list of schemes use powercfg -list, for a list of guids use powercfg -aliases