Jump to content

CMD Programming (if then)

TommyTwommy
Go to solution Solved by TommyTwommy,
netsh interface show interface name="Wi-Fi" | find /i "Disabled"
if %ERRORLEVEL% == 0 (
    netsh interface set interface Wi-Fi enable
	netsh interface set interface Ethernet disable
) else if %ERRORLEVEL% == 1 (
    netsh interface set interface Wi-Fi disable
	netsh interface set interface Ethernet enable
) else (
   echo Invalid ErrorLevel
)

ok I've managed to do it.. here is the code..

 

basically what I want to do is make a .bat file that will switch the power states of my network interfaces..

 

i have Wi-Fi and Ethernet.. if Wifi is enabled then disable it.. if Ethernet is disabled then Enable it..

 

currently I'm using 2 separate bat files, but I would like to use one instead...

 

how do I make an IF in cmd to check if

netsh interface show interface name="Wi-Fi"

outputs

Wi-Fi
   Type:                 Dedicated
   Administrative state: Disabled
   Connect state:        Disconnected

and if it does to run 2 commands

netsh interface set interface Wi-Fi enable
netsh interface set interface Ethernet disable

else

netsh interface set interface Wi-Fi disable
netsh interface set interface Ethernet enable

 

CPU & COOLER - INTEL i9 12900K | NZXT KRAKEN X62

MBO - MSI Z690 EDGE

GPU - ASUS GEFORCE RTX 3080 TUF

RAM - 2x16GB KINGSTON FURY 3200MHZ

PSU - PHANTEKS REVOLT PRO 1000W 80 PLUS GOLD

SSD #1 - CORSAIR SN850 1TB

SSD #2 - CORSAIR SN850X 4TB

SSD #3 - INTEL 660p 2TB

CASE - PHANTEKS ECLIPSE P500A D-RGB

MOUSE #1 - LOGITECH G502 X Wireless

KEYBOARD - AKKO 5108B PLUS

SPEAKERS - SVS PB-1000 + 2x ADAM A3X

HEADSET #1 - SENNHEISER IE-300

HEADSET #2 - FOSTEX TR-X00 PURPLEHREART

AMP/DAC - MAYFLOWER ARC

OS - WINDOWS 10 PRO

DISPLAY 1 - LG OLED42C2

DISPLAY 2 - XIAOMI 2K GAMING

PHONE - SAMSUNG GALAXY S23+ 

Link to comment
Share on other sites

Link to post
Share on other sites

netsh interface show interface name="Wi-Fi" | find /i "Disabled"
if %ERRORLEVEL% == 0 (
    netsh interface set interface Wi-Fi enable
	netsh interface set interface Ethernet disable
) else if %ERRORLEVEL% == 1 (
    netsh interface set interface Wi-Fi disable
	netsh interface set interface Ethernet enable
) else (
   echo Invalid ErrorLevel
)

ok I've managed to do it.. here is the code..

CPU & COOLER - INTEL i9 12900K | NZXT KRAKEN X62

MBO - MSI Z690 EDGE

GPU - ASUS GEFORCE RTX 3080 TUF

RAM - 2x16GB KINGSTON FURY 3200MHZ

PSU - PHANTEKS REVOLT PRO 1000W 80 PLUS GOLD

SSD #1 - CORSAIR SN850 1TB

SSD #2 - CORSAIR SN850X 4TB

SSD #3 - INTEL 660p 2TB

CASE - PHANTEKS ECLIPSE P500A D-RGB

MOUSE #1 - LOGITECH G502 X Wireless

KEYBOARD - AKKO 5108B PLUS

SPEAKERS - SVS PB-1000 + 2x ADAM A3X

HEADSET #1 - SENNHEISER IE-300

HEADSET #2 - FOSTEX TR-X00 PURPLEHREART

AMP/DAC - MAYFLOWER ARC

OS - WINDOWS 10 PRO

DISPLAY 1 - LG OLED42C2

DISPLAY 2 - XIAOMI 2K GAMING

PHONE - SAMSUNG GALAXY S23+ 

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

×