参考提问:Windows11 手动关闭无线网络后无法通过命令行开启
PS C:\Users\ms> Get-NetAdapter
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
蓝牙网络连接 2 Bluetooth Device (Personal Area Ne...#2 29 Disconnected 34-6F-24-99-2A-C8 3 Mbps
以太网 Realtek PCIe GbE Family Controller 28 Disconnected 50-EB-F6-30-9F-A1 0 bps
WLAN MediaTek Wi-Fi 6 MT7921 Wireless LAN... 26 Up 14-21-E1-93-A9-4F 1.2 Gbps
手动关闭 WLAN 后通过终端执行:
没有响应
Enable-NetAdapter -Name "WLAN" -Confirm:$false
提示网络不存在
netsh interface set interface name="WLAN" admin=enable
运行日志
PS C:\Users\ms> netsh interface set interface name="WLAN" admin=enable
此网络连接不存在。
什么逻辑呢,WLAN 开启状态下,打开终端管理员,可以通过命令,启动和关闭命令。
netsh interface set interface name="WLAN" admin=disable
netsh interface set interface name="WLAN" admin=enable
Disable-NetAdapter -Name "WLAN" -Confirm:$false
Enable-NetAdapter -Name "WLAN" -Confirm:$false
以上命令在无线网络开启状态下正常启动和关闭 wifi
但是手动关闭 WLAN 后
就不能同命令行开启 WLAN
希望有技术的大佬,交流交流经验。 感谢大佬了~
1
NoOneNoBody 3 天前
netsh wlan connect 参数?
没这样玩过,你需求是程序启动? |
![]() |
2
kokutou 3 天前 via Android
没找到 我怀疑是 gui 显示
因为你关了马上开,ssid 还是那些啊,感觉跟没关一样。。。 |
![]() |
3
redtears 3 天前
https://learn.microsoft.com/en-us/answers/questions/2074409/resolved-how-to-toggle-wi-fi-in-windows-11-via-the
```shell [CmdletBinding()] Param ( [Parameter(Mandatory=$true)][ValidateSet('Off', 'On')][string]$Status ) Add-Type -AssemblyName System.Runtime.WindowsRuntime $asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0] Function Await($WinRtTask, $ResultType) { $asTask = $asTaskGeneric.MakeGenericMethod($ResultType) $netTask = $asTask.Invoke($null, @($WinRtTask)) $netTask.Wait(-1) | Out-Null $netTask.Result } [Windows.Devices.Radios.Radio,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null [Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null $radios = Await ([Windows.Devices.Radios.Radio]::GetRadiosAsync()) ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Radios.Radio]]) $wifiRadio = $radios | ? { $_.Kind -eq 'WiFi' } [Windows.Devices.Radios.RadioState,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null Await ($wifiRadio.SetStateAsync($Status)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null ``` 以上代码保存为 ToggleWifiRadio.ps1 # Turn off PS D:\path\to\your\folder> .\ToggleWifiRadio.ps1 -Status 'Off' # Turn on PS D:\path\to\your\folder> .\ToggleWifiRadio.ps1 -Status 'On' |
4
ms2297248353 OP |