I have scripted ConnInterface.bat to enable (connect) or disable (disconnect) an interface, like Local Area Connection, from the command-line.

ConnInterface.bat uses Cnic.exe which you must extracted from TechniquesForSimp2006_05.exe and stored in a folder that is in your path.

The syntax for using ConnInterface.bat is:

\[call\] ConnInterface Action InterfaceName Status


Action    is a C to connect, a D to disconnect, or and S to only return status.                              Interface is the name of the interface, like "Local Area Connection".                              Status    is a call directed environment variable that will contain the interface status                                        after the Action is performed, either C for connected, D for disconnected, or E for error.
NOTE: See tip 10620 » How can I rename an interface (Local Area Connection) from the command-line?
NOTE: See tip 3378 » How can I change the Local Area Connection name and/or the connection icon on the taskbar, using the registry?

ConnInterface.bat contains:

@echo off                              if \{%3\}==\{\} @echo Syntax: ConnInterface Action InterfaceName Status&goto :EOF                              setlocal                              set Action=%1                              set IFN=%2                              set Action=%Action:"=%                              if /i "%action%" EQU "C" goto con                              if /i "%action%" EQU "D" goto dis                              if /i "%action%" EQU "S" goto sta                              @echo Error: ConnInterface %1 %2 %3 - Action is must be C,D, or S                              endlocal                              goto :EOF                              :con                              set IC=cnic %IFN% -c -s -v                              goto doit                              :dis                              set IC=cnic %IFN% -d -s -v                              goto doit                              :sta                              set status=E                              set wrk=E                              for /f "Tokens=*" %%s in ('cnic %IFN% -s -v^|find "connected"') do (                               set wrk=%%s                              )                              set wrk=%wrk:"=%                              if "%wrk%" EQU "E" goto finish                              set wrk=%wrk:*disconnected=D%                              if "%wrk%" EQU "D" set status=D&goto finish                              set wrk=%wrk:*connected=C%                              if "%wrk%" EQU "C" set status=C                              :finish                              endlocal&set %3=%status%                              goto :EOF                              :doit                              set status=E                              for /f "Tokens=*" %%s in ('%IC%^|find "Operation succeded"') do (                               set status=Y                              )                              if "%status%" EQU "E" goto finish                              goto sta