在 Windows 上通过批处理命令禁用特定的以太网卡

在 Windows 上通过批处理命令禁用特定的以太网卡

我想要做的是根据连接名称禁用 NIC(即:您在“网络连接”窗口中看到的内容,或使用 netsh 命令使用的内容)。

我知道可以使用 devcon 来启用/禁用,但是 devcon 使用物理 NIC 的硬件 ID(例如:)来识别设备PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\4&282B82B8&0&08F0,而不是与其关联的连接的名称(例如:“本地连接 2”)。

因此基本上我需要一些东西来将连接名称映射到设备的硬件 ID,如下所示:

devcon listclass Net

然后可以通过 devcon 进行禁用。

有什么想法可以做到这一点吗? 有没有更聪明/更简单的方法可以做到这一点?

答案1

经验值(局域网有线)

这里,NetConnectionStatus=2 抓取积极的(已连接)网络接口并且“更多 +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

然后将字符串(简称为第一个 & 符号)输入到开发者大会禁用然后启用互联网连接:

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 输出很宽,因此在记事本中关闭自动换行后,如果您查看 1.txt 这样的文件,就会很清楚:

C:\>wmic.exe nic > 1.txt

C:\>1.txt


Windows 7的Wifi 连接(另一种不使用 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

答案2

要禁用名为“本地连接”的连接及其设备:

netsh interface set interface "Local Area Connection" DISABLE

验证方法如下:

netsh interface show interface

这将禁用可以使用设备管理器进行验证的网络设备。

答案3

如果你还没有,一定要看看这个家伙的研究

答案4

从这里开始 - 使用西米克会给你一些可以提供给 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

因此,使用一个 shell 脚本来查找设备ID本地连接会读,

wmic nic where(NetConnectionID="Local Area Connection") get PNPDeviceID | find "PCI\"  

您可以使用 devcon 来部分匹配设备 ID,下面是我用来禁用 70 台华硕 Eee Box B203s 中的 WLAN 的命令,

devcon disable PCI\VEN_1814*DEV_0781  

(* 只是为了代替脚本中的转义符号)

相关内容