I'm trying to create a .bat file which can enable/disable my ethernet adapter, but I don't have much knowledge about coding or the cmd syntax. I was thinking about using the netsh command in something like:
IF " ~Ethernet adapter is enabled~ " GOTO :disable ELSE GOTO :enable
:disable
netsh interface set interface "Ethernet" disabled
:enable
netsh interface set interface "Ethernet" enabled
How can I do it right?
If you are already familiar with the netsh interface
command, why don't you use it?
netsh interface show interface "Ethernet" |find "Connected" >nul && (
echo connected - disconnecting...
netsh interface set interface "Ethernet" disabled
) || (
echo disconnected - connecting
netsh interface set interface "Ethernet" enabled
)
In above solution it disconnects and connects the internet connection so I improvised like this to Toggle enable and disable Ethernet adapter and this is working perfectly for me.
This code disables adapter if it is enabled and enables if it is disabled.
netsh interface show interface "Ethernet" |find "Disabled" >nul && (
echo disabled - enabling...
netsh interface set interface "Ethernet" enabled
) || (
echo enabled - disabling
netsh interface set interface "Ethernet" disabled
)