I'm writing a batch file to create a power plan. The final intention is to include it in a setup. But when I run the setup the batch file stays stuck (the setup bat file has no Pauses). After a lot of changes and reading, I decided to start from the beginning again, and I dicovered that the same batch file works depending on the folder (there are no relative paths). These are the facts
I'm running Windows 10 Pro
File 1: C:\Users\idoblas\Desktop\powerCFG\original\POWERCFG_ES.BAT File 2: C:\Users\idoblas\Desktop\powerCFG\POWERCFG_ES.BAT
These are my tests:
- File 2 is a copy of file 1. Both have the same encoding, file size .... I have compared then using beyond compare and winmerge
- If I doubleclick file 1 it works perfectly (it will return an error asking for admin permissions) and if I run it as administrator it works also fine
- If I doubleclick file 2 it gets stuck @line 6 before the pause but it works fine when executed as administrator, this is the last line executed:
FOR /F "tokens=6" %%G IN ('powercfg /getactivescheme') DO set activeschemeGUID=%%G
- I've changed the permissions for file 2, giving everyone full control to file with no changes
- Tried in other folders and works like file 1, the problem is that in my setup the behavior is like in file 2
- If I run cmd.exe /k C:\Users\idoblas\Desktop\powerCFG\powercfg_es.bat from cmd shell it works, but from cmd window if I execute the batch file it gets also stuck
Here you are the code:
REM @echo off
SETLOCAL
REM Get GUID of current power scheme
REM tokens = 6 for spanish OS, tokens = 4 fo english OS
FOR /F "tokens=6" %%G IN ('powercfg /getactivescheme') DO set activeschemeGUID=%%G
PAUSE
REM Custom power scheme name
set custom_name=Evolv_power_plan
PAUSE
REM Check if it already exists and if it exists, get its GUID
FOR /F "tokens=6" %%G IN ('powercfg -list ^| find "%custom_name%"') DO (
REM custom power scheme with that name already exists
set custom_GUID=%%G
goto :SetCustomActive
)
PAUSE
REM Here we're sure it doesn't exist: copy current active scheme and get GUID of that copy
FOR /F "tokens=6" %%G IN ('powercfg -DUPLICATESCHEME