trante
trante

Reputation: 34006

Enable/disable network connection from command line

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.

Upvotes: 27

Views: 108823

Answers (5)

AntonyMan
AntonyMan

Reputation: 51

  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

Upvotes: 1

Yarish Kumar
Yarish Kumar

Reputation: 393

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"

Upvotes: 25

cis
cis

Reputation: 21

C:\WINDOWS\system32>netsh interface show interface

Admin State State Type Interface Name

Enabled Connected Dedicated Ethernet 2 Enabled Disconnected Dedicated Ethernet Enabled Connected Dedicated Wi-Fi

C:\WINDOWS\system32>netsh interface set interface name="Ethernet" admin=enable or disable

w10 output this..

Upvotes: 2

Aaron Thoma
Aaron Thoma

Reputation: 4036

You have to run it with elevated/ admin privileges.

(On Windows 7, I otherwise get the confusing error message

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

)

(I edited @yarish kumar's answer to reflect this.)

Upvotes: 6

CMS_95
CMS_95

Reputation: 335

okay it looks like you need to delete the profile from the table. I.E.

netsh LAN>delete "profile of LAN connection"

before this you should save the configuration info of the LAN in case you want to ADD it back it will save as an XML file then to add it back just do

netsh LAN>ADD file-name="profile1.XML" interface="Local Area Connection"

also look at http://www.computerhope.com/netsh.htm for more details about netsh commands

Hope this helps

Upvotes: 1

Related Questions