Start a Command Prompt as administrator.
To show a list with 'Interface(s) Names', 'States' and more, type the following:
netsh interface show interface
It will echo something should like this.
> netsh interface show interface
Admin State State Type Interface Name
-------------------------------------------------------------------------
Enabled Connected Dedicated Local Area Connection
Disabled Disconnected Dedicated Local Area Connection 4
- Now, pick an 'Interface Name' from your list.
for example, as you can see, mine is 'Local Area Connection'
To ENABLE the selected connection type the following:
Where is "%InterfaceName%" place your Interface Name. Beware: Close the 'Interface Name' in double quotes ["] if includes spaces, like mine for example: "Local Area Connection".
netsh interface set interface "%InterfaceName%" ENABLE
OR if doesn't work for you, try the next:
netsh interface set interface name="%InterfaceName%" admin=ENABLED
To DISABLE the selected connection type the following:
netsh interface set interface "%InterfaceName%" DISABLE
OR if doesn't work for you, try the next:
netsh interface set interface name="%InterfaceName%" admin=DISABLED
TIP: You can make a 'Restart Connection.cmd' or 'Restart Connection.bat' to do the job with just a double click. ;)
This could be like this:
@echo off
mode con: cols=80 lines=27
title Connection Restart
color 1f
cls
echo This program restarts Internet Connection adapter.
echo.
echo List of network adapters (Internet adapters)
netsh interface show interface
echo ==========================================================================
:: Setting Interface Name
set InterfaceName=Local Area Connection
:Disadling adapter
echo. & echo
echo RESTARTING "%InterfaceName%" adapter. WAIT...
netsh interface set interface "%InterfaceName%" disable
echo "%InterfaceName%" adapter disabled. Wait...
echo. & echo.==========
timeout /t 5 >nul
:Enabling adapter
netsh interface set interface "%InterfaceName%" enable
echo "%InterfaceName%" adapter Enabled. Wait...
echo. & echo.==========
echo Procedure completed successfully
timeout /t 6 >nul
EXIT
Note that the only thing you need to Replace in this Batch to make it work for you is the (exact) name of your 'Interface Name' in the 13th line.
For example, the name in BOLD:
set InterfaceName=Local Area Connection.
This line (13th) makes this variable "%InterfaceName%" so you don't need to change anything else to work. But you would experiment if you like.
Enjoy
An improved .cmd batch script version that automatically restarts the internet connection (without any else user interaction) is the following:
Applies to Windows OS(es) 7,8,10,11
Automatically gets the enabled/connected Interface Name
Supports local languages text/characters (if any)
Predicts manual name entry in case it fails. (but it wont fail)
Has visual (colors) and sound indications
The following script is totally automated, so you don't need to do anything else but a double click to run it (or else maybe will need to run it as Admin).
In this case use this "run as Admin" Tip:
You can make a shortcut of 'Connection-Restart.cmd' (eg.) on Desktop, by
1. Copy or Move the .cmd batch file (eg.) at C:\ ,
(go to the copied|moved file) R.Click > "Copy"
and then R.Click on Desktop > "Paste shortcut".
2. Set shortcut to (always) "Run as Administrator", by
R.Click on shortcut > Properties > Shortcut > Advanced > "Run as Administrator".
3. Set an icon for the shortcut, by (optional)
R.Click on shortcut > Properties > Shortcut > Change Icon...
4. From now on, when double click on the shortcut you made will always run as Admin.
Connection-Restart.cmd
@echo off
mode con: cols=80 lines=27
title Connection Restart
::The following two lines stands for Local language(s) support (just in case, if any).
setlocal enableextensions
%SystemRoot%\System32\chcp.com 65001 >nul
:Starting message
color 1f && cls
echo This program restarts Internet-adapter.
:List adapters
echo.
echo. List of network adapters (Internet adapters)
netsh interface show interface
echo.==========================================================================
:Getting & Setting Interface Name
for /F "skip=3 tokens=1,2,3* delims= " %%G in ('netsh interface show interface') DO (
if /i "%%G"=="Enabled" (
if /i "%%H"=="Connected" (
set InterfaceName=%%J
)))
:Disabling adapter
color 1f
echo. & echo.
echo RESTARTING "%InterfaceName%" adapter. Wait...
netsh interface set interface "%InterfaceName%" disable
if %errorlevel% NEQ 0 call :SET MANUALLY
echo "%InterfaceName%" adapter disabled. Wait...
echo. & echo.(♪) ==========
::just a flashing color indication
color 1E && timeout /t 1 >nul && color 1f && timeout /t 1 >nul && color 1E && timeout /t 1 >nul && color 1f && timeout /t 1 >nul && color 1E && timeout /t 1 >nul
:Enabling adapter
color 1f
netsh interface set interface "%InterfaceName%" enable
echo "%InterfaceName%" adapter Enabled. Wait...
echo. & echo.(♪) ==========
echo. & echo. Procedure(s) completed successfully.
::just a flashing color indication
color 1f && timeout /t 1 >nul && color 1f && timeout /t 1 >nul && color 2f && timeout /t 1 >nul && color 1f && timeout /t 1 >nul && color 2f && timeout /t 1 >nul && color AF && timeout /t 1 >nul
EXIT
:SET MANUALLY
color 4f
echo. (!) Sorry, you must edit Interface Name manually... (♪)
echo. (i) Pick an 'Interface Name' from above list.
set /p InterfaceNameTyped=Type it here:
set InterfaceName=%InterfaceNameTyped%
GOTO :Disabling adapter
:: https://stackoverflow.com/questions/19831023/enable-disable-network-connection-from-command-line/67591921#67591921
Note that near the (♪) ACSII symbols (Alt+NumPad#13), there is another ACSII code-character (BELL) (Alt+NumPad#07) which produces a beep sound. This cannot be passed to this stackoverflow.com code window, so you have to place it manually if you want to hear sound.
Enjoy more ;)