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 ?

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

3 Answers

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.

link|improve this answer
feedback

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

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

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)

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

Your Answer

 
or
required, but never shown