27

I know that there exists ton of results in Google for this: results, but I didn't make it in my Windows XP machine. I want to disable LAN connection from command line.

>netsh interface set interface "Local Area Connection" DISABLED
One or more essential parameters not specified
The syntax supplied for this command is not valid. Check help for the correct sy
ntax.

>netsh interface set interface name="Local Area Connection" admin="disabled"
One or more essential parameters not specified
The syntax supplied for this command is not valid. Check help for the correct sy
ntax.

>netsh interface set interface name="Local Area Connection" admin=DISABLED
One or more essential parameters not specified
The syntax supplied for this command is not valid. Check help for the correct sy
ntax.
3
  • first let me ask why you are doing this? second if your are trying to disable LAN why not set it in the control panel Commented Nov 18, 2013 at 1:50
  • Because two LANs doesn't work together. So I eed to fisable one if them. I don't want to disable it manually I need to disable enable automatically with bat file. Commented Nov 18, 2013 at 4:37
  • okay I see where you are going let me look at some stuff and I let ya know. Commented Nov 18, 2013 at 13:47

5 Answers 5

25

For the first two commands, you need elevated/ administrator rights:

Disable the LAN network connection

C:\> netsh interface set interface name="Local Area Connection" admin=disabled

Enable the LAN network connection

C:\> netsh interface set interface name="Local Area Connection" admin=enabled

assumption : your interface was named as "Local Area Connection" else substitute proper name. Use netsh interface show interface to find the name.

List Wifi profiles

C:\> netsh wlan show profiles

Connect to Wifi profile

C:\> netsh wlan connect name="ProfileName"
Sign up to request clarification or add additional context in comments.

2 Comments

When run without elevated/ admin privileges, the first command fails, claiming "An interface with this name is not registered with the router.".
Is there a way to achieve this without admin privileges?
6

You have to run it with elevated / administrator privileges.

I get otherwise on Windows 7 the confusing error message:

An interface with this name is not registered with the router.

Comments

2

There is output with the following netsh command line on Windows 10 or Windows 11:

netsh interface show interface

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled        Connected      Dedicated        Ethernet 2
Enabled        Disconnected   Dedicated        Ethernet
Enabled        Connected      Dedicated        Wi-Fi

The following command disables the specified network interface on execution in a command prompt window opened as administrator:

netsh interface set interface name="Ethernet" admin=disable

There can be used the following command line in a command prompt window opened as administrator to enable a network interface:

netsh interface set interface name="Ethernet" admin=enable

Comments

1
  1. Start a Command Prompt as administrator.

  2. 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
  1. 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 ;)

Comments

1

The LAN network profiles are shown on execution of the command line:

netsh lan show profiles

The configuration information of a LAN network profile should be saved before deleting it in case of wanting to add it back in future.

netsh lan export profile folder="%USERPROFILE%"

A profile could be deleted now from the LAN network profiles table.

netsh lan delete profile "profile name" 

The LAN network profile can be added again with:

netsh lan add profile filename="%USERPROFILE%\profile name.xml" interface="Local Area Connection"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.