通过命令提示符或 powershell 在 windows 10 中更改 Wi-Fi 软件的无线电状态
Changing radio status of Wi-Fi software in windows 10 via command prompt or powershall
当我们在互联网上搜索如何使用命令提示符打开 wifi 时,所有解决方案都是关于如何禁用 WLAN 适配器,这可以通过 netsh 命令简单地实现,但我正在寻找的是如何打开或关闭我的wifi 无需禁用网络适配器。
经过一番挖掘,我发现了这个
在这两种情况下都启用了 wifi 适配器
当我们 运行 Netsh WLAN show interface while wifi is on 我们得到这个
There is 1 interface on the system:
Name : Wi-Fi
Description : Qualcomm Atheros AR956x Wireless Network Adapter
GUID : e1e71fab-3a91-4b36-a65b-2c68239b729f
Physical address : 24:fd:52:af:76:92
State : disconnected
Radio status : Hardware On
Software On
Hosted network status : Not started```.
But when wifi is off same command gives this.
```netsh wlan>show interface
There is 1 interface on the system:
Name : Wi-Fi
Description : Qualcomm Atheros AR956x Wireless Network Adapter
GUID : e1e71fab-3a91-4b36-a65b-2c68239b729f
Physical address : 24:fd:52:af:76:92
State : disconnected
Radio status : Hardware On
Software Off
Hosted network status :Not started```
So what I want is to change this radio status of software via command prompt or powershall
Please help me guys.
查看这些帖子,他们讨论的正是您想要实现的目标。
https://www.reddit.com/r/sysadmin/comments/9az53e/need_help_controlling_wifi/
https://superuser.com/questions/1168551/turn-on-off-bluetooth-radio-adapter-from-cmd-powershell-in-windows-10/1293303#1293303
摘自 Reddit,
感谢 Reddit 用户 All_Front_Random 和超级用户 Ben N
要关闭 WiFi 无线电:
./Set-NetAdapterRadioPowerState.ps1 -WifiStatus Off`
打开 WiFi 无线电:
./Set-NetAdapterRadioPowerState.ps1 -WifiStatus On`
您或许可以稍微修改一下,以便它检查当前状态并简单地打开或关闭它。如果您有任何问题,请告诉我。
# 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
编辑:包含代码
这些是在命令提示符下有效的命令
检查收音机状态(无需管理员权限)
powershell Get-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable"
打开收音机(运行 作为管理员)
powershell Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable" -RegistryValue "1"
关闭无线电(运行 作为管理员)
powershell Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable" -RegistryValue "0"
要在 powershell 中使用这些命令,只需从开头删除 powershell
当我们在互联网上搜索如何使用命令提示符打开 wifi 时,所有解决方案都是关于如何禁用 WLAN 适配器,这可以通过 netsh 命令简单地实现,但我正在寻找的是如何打开或关闭我的wifi 无需禁用网络适配器。 经过一番挖掘,我发现了这个 在这两种情况下都启用了 wifi 适配器 当我们 运行 Netsh WLAN show interface while wifi is on 我们得到这个
There is 1 interface on the system:
Name : Wi-Fi
Description : Qualcomm Atheros AR956x Wireless Network Adapter
GUID : e1e71fab-3a91-4b36-a65b-2c68239b729f
Physical address : 24:fd:52:af:76:92
State : disconnected
Radio status : Hardware On
Software On
Hosted network status : Not started```.
But when wifi is off same command gives this.
```netsh wlan>show interface
There is 1 interface on the system:
Name : Wi-Fi
Description : Qualcomm Atheros AR956x Wireless Network Adapter
GUID : e1e71fab-3a91-4b36-a65b-2c68239b729f
Physical address : 24:fd:52:af:76:92
State : disconnected
Radio status : Hardware On
Software Off
Hosted network status :Not started```
So what I want is to change this radio status of software via command prompt or powershall
Please help me guys.
查看这些帖子,他们讨论的正是您想要实现的目标。
https://www.reddit.com/r/sysadmin/comments/9az53e/need_help_controlling_wifi/ https://superuser.com/questions/1168551/turn-on-off-bluetooth-radio-adapter-from-cmd-powershell-in-windows-10/1293303#1293303
摘自 Reddit, 感谢 Reddit 用户 All_Front_Random 和超级用户 Ben N
要关闭 WiFi 无线电:
./Set-NetAdapterRadioPowerState.ps1 -WifiStatus Off`
打开 WiFi 无线电:
./Set-NetAdapterRadioPowerState.ps1 -WifiStatus On`
您或许可以稍微修改一下,以便它检查当前状态并简单地打开或关闭它。如果您有任何问题,请告诉我。
# 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
编辑:包含代码
这些是在命令提示符下有效的命令
检查收音机状态(无需管理员权限)
powershell Get-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable"
打开收音机(运行 作为管理员)
powershell Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable" -RegistryValue "1"
关闭无线电(运行 作为管理员)
powershell Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable" -RegistryValue "0"
要在 powershell 中使用这些命令,只需从开头删除 powershell