zoom38
zoom38

Reputation: 95

Create a batch file to change the power options in Windows 7

Is there a way to create batch file and place it on the desktop to change the power options in Windows 7? Specifically I have the computer set to sleep after 30 minutes. Now that I use "Serve To Me/Stream To Me" apps I want to quickly be able to change the power settings to allow continuous operation and then quickly change the power settings back to 30 minute sleep when i'm done using the streaming apps. How is this done? Can it be done?

Thanks Gary

Upvotes: 3

Views: 14141

Answers (4)

Codr
Codr

Reputation: 408

There is a free tool Insomnia to prevent your windows to go to sleep. It works for Windows 7/8/10 and comes with source code.

Another way is to use the command line tool powercfg.

Never go to standby:

powercfg -change -standby-timeout-ac 0

Go to standby in 15 minutes:

powercfg -change -standby-timeout-ac 15

Upvotes: 0

zoom38
zoom38

Reputation: 95

Thank you both for your quick replies and solutions. Lance I used yours because it was simpler, after all I'm not familiar (a true rookie) with command line programming. The following code is what worked.

(The following turns off the sleep feature.)

@echo off
powercfg -SetAcValueIndex^
 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c^
 238c9fa8-0aad-41ed-83f4-97be242c8f20^ 
 29f6c1db-86da-48c5-9fdb-f2b67b1f44da^
 000
TIMEOUT /T -1

(The following sets the sleep to activate after 1800 seconds = 30 minutes.)

@echo off
powercfg -SetAcValueIndex^
 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c^
 238c9fa8-0aad-41ed-83f4-97be242c8f20^
 29f6c1db-86da-48c5-9fdb-f2b67b1f44da^
 1800
TIMEOUT /T -1.  

Thanks Again

Gary

Upvotes: 1

Aacini
Aacini

Reputation: 67216

@echo off
setlocal EnableDelayedExpansion

echo Available power schemes:
echo/

set i=0
set "options="
for /F "tokens=2,3 delims=:()" %%a in ('powercfg /L') do if "%%b" neq "" (
   set /A i+=1
   set "options=!options!!i!"
   echo !i!. %%b
   set "scheme[!i!]=%%a"
)

echo/
choice /C %options% /N /M "Select desired scheme: "
powercfg /S !scheme[%errorlevel%]!
echo/
echo Power scheme set

Perhaps you need to change the "tokens=2,3 delims=:()" FOR options to match your version or locale. I developed this code in my Windows 8.1 Spanish version; this is an output example:

Available power schemes:

1. Certificado ENERGY STAR
2. Alto rendimiento
3. Economizador

Select desired scheme: 1

Power scheme set

Upvotes: 1

Lance
Lance

Reputation: 3932

Create or modify the power schemes you want to use.

Launch RegEdit and navigate to:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes

Look through the schemes and find the GUID (long strings of characters) of the scheme you want to use.

Create a batch file like so:

@echo off
powercfg -s (GUID of the Scheme you wish to switch to.)
pause (Optional)

Name the batch file(s) appropriately.

You will make one batch file for each scheme you want to switch to.

Upvotes: 2

Related Questions