Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://superuser.com/a/1434648
- 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
- }
- Function AwaitAction($WinRtAction) {
- $asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and !$_.IsGenericMethod })[0]
- $netTask = $asTask.Invoke($null, @($WinRtAction))
- $netTask.Wait(-1) | Out-Null
- }
- Function SetHotspot($Enable) {
- $connectionProfile = [Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetInternetConnectionProfile()
- $tetheringManager = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile($connectionProfile)
- if ($Enable -eq 1) {
- if ($tetheringManager.TetheringOperationalState -eq 1)
- {
- "Hotspot is already On!"
- }
- else{
- "Hotspot is off! Turning it on"
- Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
- }
- }
- else {
- if ($tetheringManager.TetheringOperationalState -eq 0)
- {
- "Hotspot is already Off!"
- }
- else{
- "Hotspot is on! Turning it off"
- Await ($tetheringManager.StopTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
- }
- }
- }
- Function ToggleHotspot($Delay) {
- SetHotspot(1)
- sleep -seconds $Delay
- SetHotspot(0)
- sleep -seconds $Delay
- SetHotspot(1)
- }
- ToggleHotspot(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement