Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

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
PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\4&1F7DBC9F&1&30F0

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

C:\>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
12
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
PNPDeviceID
PCI\VEN_8086&DEV_10BD&SUBSYS_10FD1734&REV_02\3&33FD14CA&0&C8

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

 
discard

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