Changing radio status of Wi-Fi software in windows 10 via command prompt or powershall

佐手、 提交于 2020-06-13 09:10:11

问题


When we search on internet about how to turn on wifi using command prompt all solutions are about how to disable WLAN adapter which can be simply achieved by netsh command but what I was looking for is how to turn on or off my wifi without disabling network adapter. After some digging what I found is this In both cases wifi adaptor is enabled When we run Netsh WLAN show interface while wifi is on we get this


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.

回答1:


Check these posts they discuss exactly the things you want to achieve.

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

Excerpt from Reddit, Credit goes to Reddit user All_Front_Random and Superuser Ben N

To turn off the WiFi radio:

./Set-NetAdapterRadioPowerState.ps1 -WifiStatus Off`

To turn on the WiFi radio:

./Set-NetAdapterRadioPowerState.ps1 -WifiStatus On`

You could probably rework this a bit so that it checks the current status and simply toggles it on or off. Please let me know if you have any questions.

# 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

Edit: Included code



来源:https://stackoverflow.com/questions/61930470/changing-radio-status-of-wi-fi-software-in-windows-10-via-command-prompt-or-powe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!