4

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 ?

nray
  • 1,540
  • 17
  • 23

4 Answers4

3

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
gseattle
  • 131
  • 2
1

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.

Oskar Duveborn
  • 10,760
  • 3
  • 33
  • 48
0

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

blank3
  • 2,237
  • 1
  • 16
  • 14
0

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)

nray
  • 1,540
  • 17
  • 23
  • This is probably even easier in Powershell, especially since you need the WMI query. – nray Oct 23 '09 at 14:47