Disable a specific ethernet card via batch commands on Windows
Solution 1
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
Solution 2
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.
Related videos on Youtube
nray
Updated on September 17, 2022Comments
-
nray over 1 year
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 ?
-
Admin over 14 yearsWhy not netsh? .
-
-
nray over 14 yearsThis is a good read - it's amazing how difficult this is, really.
-
nray over 14 yearsThis is probably even easier in Powershell, especially since you need the WMI query.