Jump to content

How to make a toggle switch in batch file ?

Go to solution Solved by Jacques Cartier,
18 minutes ago, badreg said:

Read the current priority and use a conditional statement to switch to the other condition.

 


set processName=ScpService.exe
set "WMIC_CMD=wmic process where name^='%processName%' get /format:list ^| findstr Priority"

for /f "tokens=1* delims==" %%A in ('%WMIC_CMD%') do set priority=%%B

if %priority% == 8 (
    wmic process where name^="%processName%" CALL setpriority "high priority"
) else (
    wmic process where name^="%processName%" CALL setpriority "normal"
)

 

Thank you very much ! It's working. I asked my question on tomshardware and 10forum. Someone told me It wasn't possible, another one suggest a script 100 times bigger. Thank you for your help, it's really appreciated.

How to toggle between this:

 

wmic process where name="ScpService.exe" CALL setpriority "high priority"

 

and this:

 

wmic process where name="ScpService.exe" CALL setpriority "normal"

 

When set to high, toggle to normal and when set to normal, toggle to high. Without creating 2 differents batch files.

Link to comment
Share on other sites

Link to post
Share on other sites

Read the current priority and use a conditional statement to switch to the other condition.

 

set processName=ScpService.exe
set "WMIC_CMD=wmic process where name^='%processName%' get /format:list ^| findstr Priority"

for /f "tokens=1* delims==" %%A in ('%WMIC_CMD%') do set priority=%%B

if %priority% == 8 (
    wmic process where name^="%processName%" CALL setpriority "high priority"
) else (
    wmic process where name^="%processName%" CALL setpriority "normal"
)

 

Link to comment
Share on other sites

Link to post
Share on other sites

18 minutes ago, badreg said:

Read the current priority and use a conditional statement to switch to the other condition.

 


set processName=ScpService.exe
set "WMIC_CMD=wmic process where name^='%processName%' get /format:list ^| findstr Priority"

for /f "tokens=1* delims==" %%A in ('%WMIC_CMD%') do set priority=%%B

if %priority% == 8 (
    wmic process where name^="%processName%" CALL setpriority "high priority"
) else (
    wmic process where name^="%processName%" CALL setpriority "normal"
)

 

Thank you very much ! It's working. I asked my question on tomshardware and 10forum. Someone told me It wasn't possible, another one suggest a script 100 times bigger. Thank you for your help, it's really appreciated.

Link to comment
Share on other sites

Link to post
Share on other sites

On 12/19/2019 at 10:13 PM, badreg said:

Read the current priority and use a conditional statement to switch to the other condition.

 


set processName=ScpService.exe
set "WMIC_CMD=wmic process where name^='%processName%' get /format:list ^| findstr Priority"

for /f "tokens=1* delims==" %%A in ('%WMIC_CMD%') do set priority=%%B

if %priority% == 8 (
    wmic process where name^="%processName%" CALL setpriority "high priority"
) else (
    wmic process where name^="%processName%" CALL setpriority "normal"
)

 

Can I ask you one last time for help ? Is it possible to toggle between balanced and high performance power plan ?

powercfg -s 381b4222-f694-41f0-9685-ff5bb260df2e

and 

powercfg -s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 

When set to balanced, toggle to high performance and when set to high performance, toggle to balanced. Without creating 2 differents batch files.

Link to comment
Share on other sites

Link to post
Share on other sites

On 12/19/2019 at 10:13 PM, badreg said:

Read the current priority and use a conditional statement to switch to the other condition.

 


set processName=ScpService.exe
set "WMIC_CMD=wmic process where name^='%processName%' get /format:list ^| findstr Priority"

for /f "tokens=1* delims==" %%A in ('%WMIC_CMD%') do set priority=%%B

if %priority% == 8 (
    wmic process where name^="%processName%" CALL setpriority "high priority"
) else (
    wmic process where name^="%processName%" CALL setpriority "normal"
)

 

I found the solution:


@echo off

set Balanced=381b4222-f694-41f0-9685-ff5bb260df2e

set HighPerf=8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c

for /f "tokens=2 Delims=:(" %%a in ('powercfg /getactivescheme') do for /f %%b in ("%%a") do set Active=%%b

if "%Active%"=="%Balanced%" (Powercfg /s "%HighPerf%") else (Powercfg /s "%Balanced%")

exit

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×