0

I want a shortcut that enable/disable a network card according to its status. I figured out how to enable or disable using either devcon, wmic and pnputil or found some Q&As here that suggest scripts that include conditional code but none of them works for me... the best I managed was to enable it when its disabled but the script doesnt disable it when its enabled...

this is one of the scripts that enable but do not disable:

@echo off

wmic path Win32_PnPEntity get FormFactor|find "2" >nul && goto :disable || goto :enable goto :eof :disable wmic Path Win32_PnPEntity Where "Name='Realtek Gaming GbE Family Controller'" Call Disable goto :eof :enable wmic Path Win32_PnPEntity Where "Name='Realtek Gaming GbE Family Controller'" Call enable goto :eof

and this is another one

@echo off

for /f "tokens=3" %%a in ('devcon status *DEV_8168^|find "Device is"') do set "status=%%a" echo status is %status%

IF "%status%" == "running" ( devcon disable DEV_8168 ) ELSE ( devcon enable DEV_8168 )

This last one gives me a clue of a kind, when the device is disabled the status query echo %status% returns 'disabled' but when it is enabled it returns nothing rather than 'running', which I believe is what it should return

1 Answers1

0

SOLVED. Thanks to io-oi reply I have a working script


@echo off & setlocal

pushd %AppDir% && 2>nul =;( reg.exe query HKCU\Environment /d /e /f on|find.exe /i "Click" >nul && =;( netsh.exe interface set interface name="Ethernet" admin=Disabled netsh.exe interface set interface name="WiFi" admin=Enabled setx.exe Click off >nul & endlocal & goto :eof );= || =;( netsh.exe interface set interface name="Ethernet" admin=Enabled netsh.exe interface set interface name="WiFi" admin=Disabled setx.exe Click on 1>nul & endlocal & goto :eof );= );=