Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I would like to do is disable a NIC based on the connection name (aka: what you see in the "network connections" window, or what you would use with netsh commands).

I know enabling/disabling can be done using devcon, however devcon identifies the device using the hardware ID of the physical NIC (e.g.: PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\4&282B82B8&0&08F0), not the name of the connection associated with it (e.g.: "Local area connection 2").

So basically I need something to map the connection name to the hardware ID of the device as returned by:

devcon listclass Net

Then disabling can be done via devcon.

Any idea on how to do that ? Any smarter/simpler way of doing that ?

share|improve this question
Why not netsh? . – Oskar Duveborn Oct 26 '09 at 9:11

XP (Lan Wired)

Here, NetConnectionStatus=2 grabs the active (connected) network interface and 'more +1' skips the header line:

C:\>wmic.exe nic where "NetConnectionStatus=2" get PNPDeviceID |more +1

Then feeding the string (up to the first ampersand for short) to devcon to disable and then enable the internet connection:

C:\>devcon.exe disable PCI\VEN_10EC
PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\4&1F7DBC9F&1&30F0: Disabled
1 device(s) disabled.

C:\>devcon.exe enable PCI\VEN_10EC
PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\4&1F7DBC9F&1&30F0: Enabled
1 device(s) enabled.

wmic output is wide so with wordwrap off in Notepad if you take a look at 1.txt like this it is fairly clear:

C:\>wmic.exe nic > 1.txt


Windows 7 Wifi Connection (another approach sans devcon.exe)

This worked for me:

C:\>wmic.exe nic where "NetConnectionStatus=2" get Index |more +1
C:\>wmic.exe path win32_networkadapter where index=12 call disable
C:\>wmic.exe path win32_networkadapter where index=12 call enable
share|improve this answer

To disable the connection named Local Area Connection and hence its device:

netsh interface set interface "Local Area Connection" DISABLE

To verify this:

netsh interface show interface

This will disable the network device which can be verified using device manager.

share|improve this answer

If you haven't yet, definatelly check this guy's research.

share|improve this answer
This is a good read - it's amazing how difficult this is, really. – nray Oct 23 '09 at 14:45

Here's a start - using wmic will get you something you can feed to devcon,

wmic:root\cli>nic where(NetConnectionID="Local Area Connection") get PNPDeviceID

So a shell script to find the Device ID of Local Area Connection would read,

wmic nic where(NetConnectionID="Local Area Connection") get PNPDeviceID | find "PCI\"

You can use devcon with partial matches of the device id, here's a command I used to disable the WLAN in 70 Asus Eee Box B203s,

devcon disable PCI\VEN_1814*DEV_0781

(the * is just instead of escaping the ampersand in the script)

share|improve this answer
This is probably even easier in Powershell, especially since you need the WMI query. – nray Oct 23 '09 at 14:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.