我想要做的是禁用基于连接名称的网卡(又名:你在“networking连接”窗口中看到的,或者你将使用netsh命令)。
我知道启用/禁用可以使用devcon完成,但devcon使用物理NIC的硬件ID(例如: PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\4&282B82B8&0&08F0 )来PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\4&282B82B8&0&08F0 ,而不是与其关联的连接的名称(例如:“本地连接2" )。
所以基本上我需要将连接名称映射到设备的硬件ID,如下所示:
devcon listclass Net
然后禁用可以通过devcon完成。
任何想法如何做到这一点? 任何更聪明/更简单的方法呢?
XP (Lan有线)
在这里,NetConnectionStatus = 2抓取活动 (连接的)networking接口,'more +1'跳过标题行:
C:\>wmic.exe nic where "NetConnectionStatus=2" get PNPDeviceID |more +1 PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\4&1F7DBC9F&1&30F0
然后将string(简称第一个&符号)提供给devcon以禁用,然后启用互联网连接:
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输出很宽,所以在记事本中closureswordwrap,如果你看看这样的1.txt,这很清楚:
C:\>wmic.exe nic > 1.txt
C:\>1.txt
Windows 7 Wifi连接(另一种方法sans devcon.exe)
这对我工作:
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
要禁用名为“本地连接”的连接以及其设备:
netsh interface set interface "Local Area Connection" DISABLE
要validation这一点:
netsh interface show interface
这将禁用可以使用设备pipe理器进行validation的networking设备。
如果你还没有,明确地检查这家伙的研究 。
这是一个开始 – 使用wmic会给你一些你可以喂给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
因此,用于查找本地连接的设备ID的shell脚本将被读取,
wmic nic where(NetConnectionID="Local Area Connection") get PNPDeviceID | find "PCI\"
您可以使用设备ID的部分匹配devcon,这里是一个命令,我用来禁用70华硕Eee Box B203s WLAN,
devcon disable PCI\VEN_1814*DEV_0781
(*仅仅是代替脚本中的&符号)