更新时间:2021-09-18 22:41:02
我找不到任何以编程方式执行此操作的方法,因此我认为答案可能是(目前)并非完全可能.
I can't find any way to do this programmatically, and as a result I think the answer might be that it's (currently) not entirely possible.
我发现当您使用 Windows 操作中心的按钮关闭 Wifi 时,netsh
将界面显示为硬件开启"软件关闭":
What I have found is that when you use the button in the Windows action center to turn off Wifi, netsh
shows the interface as "Hardware On" "Software Off":
Netsh WLAN show interfaces
There is 1 interface on the system:
Name : WiFi
State : disconnected
Radio status : Hardware On
Software Off
但是,我看不到任何通过 netsh
或任何 *-netadapter
cmdlet 触发软件关闭"的功能.这可能是通过注册表中的一个开关控制的,但如果是这样,我看不到哪个.
However I can't see any ability to trigger "Software Off" via netsh
or any of the *-netadapter
cmdlets. It might be that this is controlled via a switch in the registry but if so I can't see which.
我的建议是通过使用 Disable-NetAdapter
和 Enable-NetAdapter
启用/禁用底层适配器来继续控制 wifi,或者如果您需要保持硬件启用(也许是为了重新配置它?)但希望在这样做时断开无线连接,您可以通过以下方式连接/断开网络:
My recommendation would be to just continue controlling wifi by enabling/disabling the underlying adapter with Disable-NetAdapter
and Enable-NetAdapter
or if it's the case that you need to keep the hardware enabled (perhaps in order to reconfigure it?) but want the wireless to be disconnected while you do so, you could connect/disconnect the network via:
netsh wlan disconnect
netsh wlan connect