有什么帮助,我该如何在 Windows 11 上打开/关闭软件无线电状态?这是我的 Wi-Fi 状态:
Netsh WLAN show interfaces
There is 1 interface on the system:
Name : Wi-Fi
Description : Killer Wireless-n/a/ac Wireless Network Adapter
GUID : xx
Physical address : xx
Interface type : Primary
State : disconnected
Radio status : Hardware On
Software Off
Hosted network status : Not available
我已经尝试过命令Enable-NetAdapter
和Disable-NetAdapter
,但这些命令是针对特定的网络接口的,而不是用于广义上禁用已启用的 WiFi。
其他用户建议使用此命令,但这不会在软件模式下启用或禁用 WiFi:
netsh interface set interface name="Wi-Fi" admin=DISABLED
答案1
解决方案与建议的相同@Diskoteket:
# Set-NetAdapterRadioPowerState.ps1
# credit to ben-n on superuser; adapted from https://superuser.com/a/1293303
[CmdletBinding()] Param (
[Parameter(Mandatory=$true)][ValidateSet('Off', 'On')][string]$WifiStatus
)
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]])
$wifi = $radios | ? { $_.Kind -eq 'WiFi' }
[Windows.Devices.Radios.RadioState,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
Await ($wifi.SetStateAsync($WifiStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
然后在我的系统版本中从 powershell 5 ( ) 运行它5.1.22000.282
。
不要使用 powershell 7 (当前最新版本7.2.1
,位置C:\Program Files\PowerShell\7\pwsh.exe
),因为它不起作用。
激活后的结果(未连接到任何 wifi,因为它通过 RJ45 连接,这是优先的):
.\Set-NetAdapterRadioPowerState.ps1 -WifiStatus On
Netsh WLAN show interfaces
There is 1 interface on the system:
Name : Wi-Fi
Description : Killer Wireless-n/a/ac Wireless Network Adapter
GUID : xx
Physical address : xx
Interface type : Primary
State : disconnected
Radio status : Hardware On
Software On
Hosted network status : Not available
启用或禁用
.\Set-NetAdapterRadioPowerState.ps1 -WifiStatus On
.\Set-NetAdapterRadioPowerState.ps1 -WifiStatus Off
或者如果没有争论的话就会询问。