Short way to change power scheme

Discussion in 'Scripting' started by Javac75, Dec 7, 2020.

Tags:
  1. Javac75

    Javac75 MDL Junior Member

    Mar 16, 2015
    89
    63
    0
    #1 Javac75, Dec 7, 2020
    Last edited: Dec 8, 2020
    I'm created a simple script for changing power setting with quickly.
    You can choice a number for any exist power schemes in your system.
    But you must customize the monitor timeout first as you want. Defalut is never (0).

    Code:
    @Echo Off
    Setlocal EnableDelayedExpansion
    Setlocal EnableExtensions
    
    ::Customize screen timeout in minutes
    Set "scrTM=0"
    
    Set plh=
    :stPow
    cls
    Set /a chsp = 1
    for /f "tokens=1-2 delims=:" %%p in ('powercfg -l') do (
        if defined plh (
            IF !chsp! equ !plh! (
                for /f tokens^=1^ delims^=^  %%c in ('echo %%q') do (
                    powercfg /setactive %%c
                    echo.
                    powercfg /change monitor-timeout-ac %scrTM%
                    powercfg /change monitor-timeout-dc %scrTM%
                    echo.
                    goto :END
                )
            )
        ) else (
            IF !chsp! geq 3 echo [!chsp!] %%p %%q
        )
        Set /a chsp+=1
    )
    echo [;] Exit without change anything
    echo.
    set /p plh="type your choice, enter = "
    If %plh% geq 3 (
        if %plh% geq !chsp! Set plh=
    ) else (Set plh=)
    goto :stPow
    
    :END
    Endlocal EnableDelayedExpansion
    Endlocal EnableExtensions
    Exit

    Creat new file with anyname.cmd file, paste the code in there, launch it.
    You can put that file to windows dir, and launch it from run dialog (win+r)
    Maybe usefull for someone in audit mode system.
    Enjoy.