Batch Files

Changing Power Settings

Introduction

Some batch files take a time to run and sometimes the computer going to sleep or hibernating will cause them to not complete properly. One way around this is to go to Settings > Power & battery > Screen, sleep, & hibernate timeouts and set the timers that control these things to either "Never" or to at least a time longer than the batch file is expected to run. After the batch file is finshed, go back into the settings and put them back to whatever they were set to.

An alternative to doing that is to use powercfg from within the batch file.


Sleep and Hibernations Settings

The sleepand hibernation settings can be gotten to by going to Settings > Power & battery > Screen, sleep, & hibernate timeouts. The timings for these are initially set by Windows, and are the recommended timings.

Recommended timeout settings

The recommended timeout settings

The settings can easily be changed by using the dropdowns...

Timeout settings dropdown

The timeout settings dropdown

The dropdowns all have their separate recommended settings marked. There is no need to save the settings, they are automatically saved whenthey are changed.


Powercfg

Powercfg is a useful and versatile utility but to change the timoeut settings there is just one switch that needs to be used, the /change or /X switch.

The switch accepts two arguments, the setting to change and the value to set it to. The choice of settings are

monitor-timeout-ac
monitor-timeout-dc
disk-timeout-ac
disk-timeout-dc
standby-timeout-ac
standby-timeout-dc
hibernate-timeout-ac
hibernate-timeout-dc

The values are set in minutes and to set them to "Never" the value of zero is used.

To change the sleep and hibernation periods to "Never" then following lines can be added to a batch file:

powercfg /change standby-timeout-ac 0
powercfg /change hibernate-timeout-ac 0

By going to Settings > Power & battery > Screen, sleep, & hibernate timeouts, the changes can be seen:

Sleep and hibernate timeout settings changed to Never

The sleep and hibernate timeout settings changed to Never

To change them back to the recommended setting then the following commands can be used:

powercfg /change standby-timeout-ac 15
powercfg /change hibernate-timeout-ac 180

Remember that the values are set using minutes, so three hours for the hibernation timeout is 3 x 60 = 180.


Sources and Resources

Most useful commands for PowerCFG command line (Windows Club)
Powercfg command (Computer Hope)
Powercfg command-line options (Microsoft Learn)
PowerCFG.exe (SS64)
Unlock Windows 11 Power: The Ultimate Guide to Powerful Powercfg Commands for Advanced Energy Efficiency & Troubleshooting (Microsoft News Now)