Last active
July 7, 2019 12:45
-
-
Save basinilya/6217576bb044b4dfe23914ba0b2f3f8b to your computer and use it in GitHub Desktop.
restart-wifi-ap.bat: Solve hostednetwork failing after sleep by restarting the physical adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Auto detect text files and perform LF normalization | |
* text=auto | |
# Windows CMD does not like LF in batch files | |
*.bat text eol=crlf | |
*.cmd text eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
netsh wlan show hostednetwork 2>&1 | findstr /R /C:"^ ..:..:..:..:..:.. " || ^ | |
call %~dp0restart-wifi-ap.bat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@rem TODO: hostednetwork degrades over time. | |
@rem TODO: List clients periodically and restart if no clients | |
@rem TODO: https://superuser.com/questions/555229/it-is-possible-to-see-clients-who-connected-to-my-hostednetwork | |
@rem TODO: netsh wlan show hostednetwork | |
@rem TODO: Windows 7: | |
@rem TODO: ‘®áâ®ï¨¥ à §¬¥é¥®© á¥â¨ | |
@rem TODO: ------------------------ | |
@rem TODO: ‘®áâ®ï¨¥ : ‡ ¯ã饮 | |
@rem TODO: BSSID : 01:23:45:67:89:ff | |
@rem TODO: ’¨¯ à ¤¨®¬®¤ã«ï : 802.11n | |
@rem TODO: Š « : 11 | |
@rem TODO: —¨á«® ª«¨¥â®¢ : 1 | |
@rem TODO: 01:23:45:67:89:ab ஢¥àª ¯®¤«¨®á⨠¢ë¯®«¥ | |
@set dotfile=%~dp0dotfile.dot | |
@set sleepcommand=ping 127.0.0.1 -w 1 -n | |
@echo %date% %time% | |
netsh interface set interface "Wireless Network Connection" disable | |
@echo %date% %time% | |
netsh interface set interface name="Wireless Network Connection" enable | |
:MOO | |
@echo %date% %time% | |
@set tmo=10 | |
:LOO | |
@if %tmo%==0 goto :OK | |
@type %dotfile% | |
@%sleepcommand% 2 >nul | |
@set /A tmo=tmo-1 | |
@goto :LOO | |
:OK | |
@echo. | |
@echo %date% %time% | |
netsh wlan start hostednetwork || @goto :MOO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schtasks /create /xml "schtasks-restart-wifi-ap.xml" /tn "restart-wifi-ap" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | |
<RegistrationInfo> | |
<Date>2019-06-11T05:36:02.2715853</Date> | |
<Author>MAR2\il</Author> | |
</RegistrationInfo> | |
<Triggers> | |
<EventTrigger> | |
<Enabled>true</Enabled> | |
<Subscription><QueryList><Query Id="0" Path="Microsoft-Windows-Diagnostics-Performance/Operational"><Select Path="Microsoft-Windows-Diagnostics-Performance/Operational">*[System[Provider[@Name='Microsoft-Windows-Diagnostics-Performance'] and EventID=300]]</Select></Query></QueryList></Subscription> | |
</EventTrigger> | |
</Triggers> | |
<Principals> | |
<Principal id="Author"> | |
<UserId>S-1-5-18</UserId> | |
<RunLevel>LeastPrivilege</RunLevel> | |
</Principal> | |
</Principals> | |
<Settings> | |
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> | |
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> | |
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> | |
<AllowHardTerminate>true</AllowHardTerminate> | |
<StartWhenAvailable>false</StartWhenAvailable> | |
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> | |
<IdleSettings> | |
<StopOnIdleEnd>true</StopOnIdleEnd> | |
<RestartOnIdle>false</RestartOnIdle> | |
</IdleSettings> | |
<AllowStartOnDemand>true</AllowStartOnDemand> | |
<Enabled>true</Enabled> | |
<Hidden>false</Hidden> | |
<RunOnlyIfIdle>false</RunOnlyIfIdle> | |
<WakeToRun>false</WakeToRun> | |
<ExecutionTimeLimit>P3D</ExecutionTimeLimit> | |
<Priority>7</Priority> | |
</Settings> | |
<Actions Context="Author"> | |
<Exec> | |
<Command>C:\keep\restart-wifi-ap.bat</Command> | |
<Arguments>>>restart-wifi-ap.log 2>&1</Arguments> | |
<WorkingDirectory>C:\keep</WorkingDirectory> | |
</Exec> | |
</Actions> | |
</Task> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment