How do i change the powerplan automatically when a .exe opens (any app or game)

Alberto Bj

Distinguished
Oct 16, 2015
243
0
18,690
Hello , i wanted to change my Power settings to high performance when launching a game, i don't want to use gameboosters. Can someone help me on how to create a batch file that makes the power plan Switch to whatever powerplan i want it to switch to when a certain condition is met (e.g. when opening a game or an app), then reverts back when the certain game or app closes?

thanks.
 
Solution

A game launcher complicates the problem with batch files because I don't know of a way in a batch file to detect when the game...
Open command prompt and type: powercfg /list
This will list the existing power schemes along with their GUIDs (that big long string of numbers and characters).

To switch between power schemes, you can use the command:
powercfg -s GUID
except replace GUID with that big long string of numbers and characters.

Screenshots that I just took (latest Win10, all updates):

image.jpg

image.jpg

So now that you know how to change power plans with the command prompt, you also need to know how to run a game and wait for it to finish before continuing with the batch file. You can do this with the start command and use the /wait parameter. Example:
start "" /wait "c:\program files (x86)\game\game1.exe"
Important: The two quotes near the beginning are needed. The start command expects you type in a title for the command prompt box there, or you can just leave it blank with the empty quotes like I did. If you omit the quotes you'll have problems.

An example batch:

@echo off
powercfg -s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
start "" /wait "c:\windows\notepad.exe"
powercfg -s 381b4222-f694-41f0-9685-ff5bb260df2e


If you have the same GUIDs as I do (you probably do), then you can test the above. Create the batch file. Create a shortcut to the batch file and set the shortcut to run minimized. Open the Power Options dialog and watch it change as the batch file runs. Remember, it won't change back to Balanced until you close Notepad out!

Reference used: https://superuser.com/questions/686843/how-do-i-change-the-power-plan-using-batch
 


great help, one question tho, is it possible to make another batch file or command that makes the batch file that you created, run everytime you open a game/exe or should i just use task scheduler instead ? how do i do that

 
I don't really understand what you mean. You can create the batch file, save it, create a shortcut to it, and run it every time you run a game.

You could add the game's executable file as a parameter in the shortcut and instead of having it in the batch file use %1 instead. For example, use this batch:

@echo off
powercfg -s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
start "" /wait %1
powercfg -s 381b4222-f694-41f0-9685-ff5bb260df2e


Then in the shortcut you would call the batch up with the game's executable as a parameter. For example, if the batch file is named rungame.bat you could do this in the shortcut properties:

Target: "C:\batch\rungame.bat" "c:\program files (x86)\Game One\Game1.exe"

Then in another shortcut you could use:

Target: "C:\batch\rungame.bat" "c:\program files (x86)\Game Two\SomeOtherGame.exe"

This way you don't have to create multiple batch files. You still have to create multiple shortcuts and edit each one.

Other than that, I don't know of any way of auto changing it before a game and changing it back after a game. There might be a way and maybe someone else knows and will reply.
 


Thanks and very helpful, im asking for the purpose of not having to run the batch file again and again everytime i want to run a game.

im not really good with simple / basic commands so im still trying to absorb what you said.

so basically im going to put start "" /wait %1 instead of putting start "" /wait "c:\programfiles\game.exe"
and then in the "Game's" shortcut im going to put the directory of the batch i just created?


i don't understand what you said about "this way you don't hve to create multiple batch files. you still have to create multiple shortcuts and edit each one" by |Multiple" do you mean by creating a shortcut of the batch file and creating the shortcut of the game ?

 



Pardon me, i finally got what you said, i followed the instructions, made the bat file with
@echo off
powercfg -s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
start "" /wait %1
powercfg -s 381b4222-f694-41f0-9685-ff5bb260df2e

then made a shortcut and added the game's target

but when i run the batfile shortcut, it successfully opens the game but doesn't execute the command to switch power profiles

edit: it does switch to high performance then after one second it switches back again to balanced.

i find this very useful instead of clicking two shortcuts, i will only have to launch the game from the bat file that changes the power options (if that's how it works) and if thats how i understood it.

 
You run the shortcut to the batch file just as you would normally run the game's shortcut. So basically there is no difference, other than setting up each game to run the batch file first.


Yes, but in the shortcut, not just the directory, put the full path and filename to the game (including the .EXE file). See the examples I provided above (and below).



Basically you just have to create the batch file once. Save it to something like C:\Batch\RunGame.bat and then you need to create shortcuts for all of your games that you want to use with this batch file. In each shortcut, you simply call up the batch file and use the game's EXE file as a parameter as I described above. Set the "Run" in each shortcut to "Minimized". In the below example, the "Target" is:
C:\Batch\RunGame.bat "c:\program files\game1\game.exe"


image.jpg
 


I finally got it, the problem is the power plan changes to high performance when the game launches and then switches back to "balanced" after one second.

any help ?

EDIT:

I finally figured it out, the game i was trying to launch has two different .exe's ,the reason it switches back to "balanced" is because the process of the main game is actually different from the process of the Game's Launcher. so when i try to run the bat file, the process of the launcher opens, it closes, then the power option reverts back to "balanced"

Thanks!
 


One slight problem though, i thought i figured it out but i tried to change the "games launcher.exe" to the main "process.exe" so the power option won't turn back, but it won't launch now, so basically i need to find a way to make the performance profile change to high performance when the main process is executed, not the launcher,

can you help?

edit: i need to find a way to make the performance profile change to high performance when the main process is executed, not the launcher. WHILE having the bat file launch the launcher (because it won't work when i directly launch from the game's main process)
 

A game launcher complicates the problem with batch files because I don't know of a way in a batch file to detect when the game ends since it only sees the launcher. It isn't aware that the launcher launched a game. Launching the game directly and bypassing the launcher usually isn't allowed by game makers (or at least they don't make it easy to do if it's even possible).

So how can it be done? Probably scripting is your next best option. A script should be able to change the power scheme, run the launcher quits, detect when the game starts and ends, and change the power scheme back.

Windows supports various types of scripts, from powershell scripts to VBS and maybe others. I don't know much about either of those and only have used VBS once or twice many years ago. I prefer [AutoHotKey] (AHK), it's a popular 3rd party free scripting application.

With AHK, you install it and then have to create scripts in notepad and save them as a .AHK file (for example, RunGame.ahk). You run the script by simply double clicking on it. If you run AHK by itself it does nothing (but open the help file) as it expects a script.

While I haven't attempted such a script in AHK, I do think it can be done and am willing to try to help you out with it if you want to go that route. I can't make any promises that we will figure it out but I'm willing to give it a try.

Do you want to try AHK? If so, download and install it. Give me the full path and filenames of both the game launcher and the game exectuable. For example:
Launcher: C:\program files\game\launcher.exe
Game: C:\program files\game\game.exe
and I'll start work on a script and we'll see what happens.
 
Solution


Alright. Thanks for all your help that's all for now
 
I don't really understand what you mean. You can create the batch file, save it, create a shortcut to it, and run it every time you run a game.

You could add the game's executable file as a parameter in the shortcut and instead of having it in the batch file use %1 instead. For example, use this batch:

@echo off
powercfg -s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
start "" /wait %1
powercfg -s 381b4222-f694-41f0-9685-ff5bb260df2e


Then in the shortcut you would call the batch up with the game's executable as a parameter. For example, if the batch file is named rungame.bat you could do this in the shortcut properties:

Target: "C:\batch\rungame.bat" "c:\program files (x86)\Game One\Game1.exe"

Then in another shortcut you could use:

Target: "C:\batch\rungame.bat" "c:\program files (x86)\Game Two\SomeOtherGame.exe"

This way you don't have to create multiple batch files. You still have to create multiple shortcuts and edit each one.

Other than that, I don't know of any way of auto changing it before a game and changing it back after a game. There might be a way and maybe someone else knows and will reply.
Hi gardenman,

thanks for your tipps with the batch file here. I've also tried these out for certain programs. However, if I follow your advice with the %1 and create one batch file for several programs, it seems to work as long is I do not set the program link to be run as an administrator. Once I make the link run the bat file and the program as an administrator the %1 does not seem to work any longer and I have to insert the whole path of the program in the batch file instead. Do you know how I can make it work with the help of the %1 placeholder in the batch file for running different programs with administrator privilege? Thank you!