Skip to content

Doesn't detect change in connection, and enables/disables entire adapter instead of status #3

@ciphernemo

Description

@ciphernemo

I understand the author doesn't maintain this anymore because he no longer uses these two script files, but there are some issues for those looking to use this in the future:

  • The WLANManager.ps1 only detects combination of wired/wireless status, not changes in each status. Therefore this solution is better: Dell's recommendation
  • The WLANManager disables or enabled the entire adapter, which is not ideal. It's better to enable or disable the status. PowerShell Example:
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]
[Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime]
Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus])
$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]

Then...

Await ($wifi.SetStateAsync("Off")) ([Windows.Devices.Radios.RadioAccessStatus])

... change the the $wifi.SetStateAsync to either "On" or "Off"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions