(view source code of runbackupwithoutsleep.bat as plain text)
@ECHO OFF
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
IF "%~1"=="" GOTO Syntax
SETLOCAL
CLS
:: Check if High Performance plan can be foundPOWERCFG /List 2>&1 | FIND /I "High performance" >NUL
IF ERRORLEVEL 1 (
POWERCFG /List 2>&1 | FIND /I "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c" >NUL
IF ERRORLEVEL 1 GOTO Syntax
):: Save a list of power schemes once, before changing anythingIF NOT EXIST "%~dpn0.inital.txt" (
ECHO WARNING: Do not delete this file, it is used by %~nx0 to reactivate the original power scheme> "%~dpn0.inital.txt"
ECHO.>> "%~dpn0.inital.txt"
POWERCFG /List >> "%~dpn0.inital.txt" 2>&1
):: Find the initial power schemeFOR /F "tokens=1* delims=:" %%A IN ('TYPE "%~dpn0.inital.txt" ^| FINDSTR /R /E /C:"\*"') DO (
FOR /F "tokens=1,2 delims=()" %%C IN ("%%~B") DO (
SET PowerCfg.Initial.GUID=%%C
SET PowerCfg.Initial.Name=%%D
))FOR %%A IN (%PowerCfg.Initial.GUID%) DO SET PowerCfg.Initial.GUID=%%A
IF /I "%~1"=="/I" (
POWERCFG /SetActive %PowerCfg.Initial.GUID%
POWERCFG /List
GOTO:EOF
):: Find the high performace power schemeFOR /F "tokens=1* delims=:" %%A IN ('TYPE "%~dpn0.inital.txt" ^| FIND /I "High performance"') DO (
FOR /F "tokens=1,2 delims=()" %%C IN ("%%~B") DO (
SET PowerCfg.HighPerformance.GUID=%%C
SET PowerCfg.HighPerformance.Name=%%D
))IF "%PowerCfg.HighPerformance.GUID%"=="" (
FOR /F "tokens=1* delims=:" %%A IN ('TYPE "%~dpn0.inital.txt" ^| FIND /I "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"') DO (
FOR /F "tokens=1,2 delims=()" %%C IN ("%%~B") DO (
SET PowerCfg.HighPerformance.GUID=%%C
SET PowerCfg.HighPerformance.Name=%%D
) ))FOR %%A IN (%PowerCfg.HighPerformance.GUID%) DO SET PowerCfg.HighPerformance.GUID=%%A
:: Find the currently active schemeFOR /F "tokens=1* delims=:" %%A IN ('POWERCFG /GetActiveScheme') DO (
FOR /F "tokens=1,2 delims=()" %%C IN ("%%~B") DO (
SET PowerCfg.Current.GUID=%%C
SET PowerCfg.Current.Name=%%D
))FOR %%A IN (%PowerCfg.Current.GUID%) DO SET PowerCfg.Current.GUID=%%A
:: Display the initially and currently active schemesECHO.
ECHO Power plan at startup:
ECHO.
FOR /F "skip=1 tokens=*" %%A IN ('TYPE "%~dpn0.inital.txt" ^| FIND "*"') DO ECHO Initial %%A
FOR /F "tokens=*" %%A IN ('POWERCFG /GetActiveScheme') DO ECHO Current %%A
:: If the current scheme is not the initial one, some other process probably changed, so we'll leave it unchangedSET DoChange=1
IF /I NOT "%PowerCfg.Current.GUID%"=="%PowerCfg.Initial.GUID%" (
SET DoChange=0
ECHO As the currently active power scheme is not the initial one, this batch file
ECHO will not reactivate the initial power scheme when finished.
ECHO Use RUNBACKUPWITHOUTSLEEP /I to manually reactivate the initial power scheme.
):: Make high performance scheme the active oneIF %DoChange% EQU 1 (
ECHO.
ECHO Making "%PowerCfg.HighPerformance.Name%" the active power scheme:
ECHO.
POWERCFG /SetActive %PowerCfg.HighPerformance.GUID%
POWERCFG /List | MORE /E +3):: Start the backup task specified on the command lineSTART /B /WAIT "Backup" %*
:: Reactivate the initial power schemeIF %DoChange% EQU 1 (
ECHO.
ECHO Reactivating "%PowerCfg.Initial.Name%" power scheme:
ECHO.
POWERCFG /SetActive %PowerCfg.Initial.GUID%
) ELSE (
ECHO The power scheme at this batch file's startup was NOT the initial one.
ECHO This batch file will not reactivate the initial power scheme.
ECHO Use RUNBACKUPWITHOUTSLEEP /I to manually reactivate the initial power scheme.
ECHO.
):: Display the initially and currently active schemesPOWERCFG /List | MORE /E +3ENDLOCAL
GOTO:EOF
:SyntaxECHO.
ECHO RunBackupWithoutSleep.bat, Version 1.20 for Windows 7
ECHO Run a backup, defrag or any other long task without the computer going to sleep
ECHO.
ECHO Usage: RunBackupWithoutSleep backup_command [ backup_command_arguments ]
ECHO or: RunBackupWithoutSleep /I
ECHO.
ECHO Notes: The first time this batch file runs, it creates a list of available
ECHO Power schemes. This list will be used to restore the initial scheme.
ECHO If the currently active power scheme is not the initial one, the
ECHO batch file will not reactivate the initial power scheme, to prevent
ECHO interference with other running instances of this batch file.
ECHO In that case, the batch file will display a warning message.
ECHO The initial power scheme may be manually reactivated by running
ECHO RUNBACKUPWITHOUTSLEEP /I
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" EXIT /B 1
page last modified: 2025-10-11; loaded in 0.0084 seconds