Sysinternals Homepage
Forum Home Forum Home > Windows Discussions > Troubleshooting
  New Posts New Posts RSS Feed - Command used to disable network interface
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Command used to disable network interface

 Post Reply Post Reply Page  12>
Author
Message
fcretusys View Drop Down
Newbie
Newbie


Joined: 25 November 2006
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote fcretusys Quote  Post ReplyReply Direct Link To This Post Topic: Command used to disable network interface
    Posted: 07 January 2007 at 1:59am

Hello,

I searched on the Internet for a command to be used in cmd for disabling/enabling a network interface. Does anybody know the syntax if there is one?

Thanks and Happy New Year!

Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Status: Offline
Points: 5126
Post Options Post Options   Thanks (0) Thanks(0)   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2007 at 5:52am
Hello, fcretusys.

If you are looking for commandline programmes that come with current Windows versions and for their syntax, then this page is your friend: Command-line reference A-Z.
(You may find the same information inside your local Windows help system. )

If you jump to letter "N", you will easily find the netsh command: Using Netsh.

Yet, the description of netsh is pretty hard to read (my impression).

So I did some simple Google search and found this:

Quote netsh interface set interface <interface name> DISABLED
For example to disable an interface with its default name “Local Area Connection,” run:
netsh interface set interface “Local Area Connection” DISABLED
To enable the interface, you'd then run:
netsh interface set interface “Local Area Connection” ENABLED
(cf. here, please.)

Hope this helps.

Karl


Edited by Karlchen - 07 January 2007 at 5:52am
Back to Top
fcretusys View Drop Down
Newbie
Newbie


Joined: 25 November 2006
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote fcretusys Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2007 at 5:59am

Originally posted by Karlchen Karlchen wrote:

Hello, fcretusys.

If you are looking for commandline programmes that come with current Windows versions and for their syntax, then this page is your friend: Command-line reference A-Z.
(You may find the same information inside your local Windows help system. )

If you jump to letter "N", you will easily find the netsh command: Using Netsh.

Yet, the description of netsh is pretty hard to read (my impression).

So I did some simple Google search and found this:

Quote netsh interface set interface <interface name> DISABLED
For example to disable an interface with its default name “Local Area Connection,” run:
netsh interface set interface “Local Area Connection” DISABLED
To enable the interface, you'd then run:
netsh interface set interface “Local Area Connection” ENABLED
(cf. here, please.)

Hope this helps.

Karl

Thanks for your answer, but id does not work.

I receive the following message from Windows:

G:\a>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.

Usage set interface [name = ] IfName
             [ [admin = ] ENABLED|DISABLED
               [connect = ] CONNECTED|DISCONNECTED
               [newname = ] NewName ]

      Sets interface parameters.

      IfName  - the name of the interface
      admin   - whether the interface should be enabled (non-LAN only).
      connect - whether to connect the interface (non-LAN only).
      newname - new name for the interface (LAN only).

      Notes:
      - At least one option other than the name must be specified.
      - If connect = CONNECTED is specified, then the interface
        is automatically enabled even if the admin = DISABLED
        option is specified.

 

G:\a>

 

I have searched on the Internet and found the following script which works:

Const ssfCONTROLS = 3

sConnectionName = "Local Area Connection"

sEnableVerb = "En&able"
sDisableVerb = "Disa&ble"

set shellApp = createobject("shell.application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)

set oNetConnections = nothing
for each folderitem in oControlPanel.items
if folderitem.name = "Network and Dial-up Connections" then
set oNetConnections = folderitem.getfolder: exit for
end if
next

if oNetConnections is nothing then
msgbox "Couldn't find 'Network and Dial-up Connections' folder"
wscript.quit
end if

set oLanConnection = nothing
for each folderitem in oNetConnections.items
if lcase(folderitem.name) = lcase(sConnectionName) then
set oLanConnection = folderitem: exit for
end if
next

if oLanConnection is nothing then
msgbox "Couldn't find '" & sConnectionName & "' item"
wscript.quit
end if

bEnabled = true
set oEnableVerb = nothing
set oDisableVerb = nothing
s = "Verbs: " & vbcrlf
for each verb in oLanConnection.verbs
s = s & vbcrlf & verb.name
if verb.name = sEnableVerb then
set oEnableVerb = verb
bEnabled = false
end if
if verb.name = sDisableVerb then
set oDisableVerb = verb
end if
next

'debugging displays left just in case...
'
'msgbox s ': wscript.quit
'msgbox "Enabled: " & bEnabled ': wscript.quit

'not sure why, but invokeverb always seemed to work
'for enable but not disable.
'
'saving a reference to the appropriate verb object
'and calling the DoIt method always seems to work.
'
if bEnabled then
' oLanConnection.invokeverb sDisableVerb
oDisableVerb.DoIt
else
' oLanConnection.invokeverb sEnableVerb
oEnableVerb.DoIt
end if

'adjust the sleep duration below as needed...
'
'if you let the oLanConnection go out of scope
'and be destroyed too soon, the action of the verb
'may not take...
'
wscript.sleep 1000

If there is a more easier way of enabling/disabling an interface, kindly let me know.

Best regards, 

 

Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Status: Offline
Points: 5126
Post Options Post Options   Thanks (0) Thanks(0)   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2007 at 6:12am
Hi, fcretusys.

Quote Thanks for your answer, but id does not work.

I am sorry.
Not wishing to kill the NIC of the machine I am using to write this, I did not test the command lines found using Google.

There must be some (minor?) syntactical flaw in that commandline. I think I will try it one of the virtual machines in the office.

Karl
Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Status: Offline
Points: 5126
Post Options Post Options   Thanks (0) Thanks(0)   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2007 at 7:45am
Hi, fcretusys.

Did some more searching. And guess I found the same script you use in the same HP ITRC Forum thread.

Also found this MS KB article which may indicate that the netsh command I found and gave you ought to work, but does not do so (not at all or unreliably):
You receive an error message when you use Netsh.exe to enable or disable a network adapter in Windows XP and in Windows 2000.

Maybe an MS commandline replacement for devmgmt.msc offers a reliable way of achieving your goal:
The DevCon command-line utility functions as an alternative to Device Manager.
(Note: have not downloaded and tested it so far)

But I'd definitely say, "Handle with care!"

Karl
Back to Top
fcretusys View Drop Down
Newbie
Newbie


Joined: 25 November 2006
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote fcretusys Quote  Post ReplyReply Direct Link To This Post Posted: 08 January 2007 at 4:20pm

The command

netsh interface set interface "Local Area Connection" DISABLED

works on Windows 2003 Server.

Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Status: Offline
Points: 5126
Post Options Post Options   Thanks (0) Thanks(0)   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 08 January 2007 at 4:26pm
OK, this confirms what I remember having read in some MS article(s): that "netsh" behaves differently on different Windows versions.

As it did not work for you I assume you were mainly trying to use it on Win2K?!

Karl
Back to Top
fcretusys View Drop Down
Newbie
Newbie


Joined: 25 November 2006
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote fcretusys Quote  Post ReplyReply Direct Link To This Post Posted: 08 January 2007 at 4:55pm

Originally posted by Karlchen Karlchen wrote:

OK, this confirms what I remember having read in some MS article(s): that "netsh" behaves differently on different Windows versions.

As it did not work for you I assume you were mainly trying to use it on Win2K?!

Karl

I wanted this command to work on Windows XP SP2.

Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Status: Offline
Points: 5126
Post Options Post Options   Thanks (0) Thanks(0)   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2007 at 6:18am
I see. Anyway, I guess that this is the situation where the workaround described by MS in their KB article applies:

You receive an error message when you use Netsh.exe to enable or disable a network adapter in Windows XP and in Windows 2000

The workaround basically is to assign an IP address and a standard gateway to the card which will make it invisible to the rest of the world.

Karl
Back to Top
6spam6 View Drop Down
Newbie
Newbie


Joined: 22 October 2008
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote 6spam6 Quote  Post ReplyReply Direct Link To This Post Posted: 22 October 2008 at 9:28am
hi
try this

http://www.wlanbook.com/enable-disable-wireless-card-command-line/

Edited by 6spam6 - 22 October 2008 at 9:29am
Back to Top
 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down