I came up with a custom solution with the help of Moshe Katz answer (thanks Moshe Katz!) which works well for my 100 laptops.
Save the following text as wifiswitch.bat file under C:\windows\system32. Make sure to check the interface names on the laptop matches the scripts:
@echo off
Title Wifi Lan Switcher
set a=0
:loop
netsh interface show interface name="Local Area Connection" | find /i "disconnected" > NUL 2>&1
IF ERRORLEVEL 1 (
netsh interface show interface name="Wireless Network Connection" | find /i "disabled" > NUL 2>&1
IF ERRORLEVEL 1 (
netsh interface set interface name="Wireless Network Connection" disable > NUL 2>&1
set error=%errorlevel%
ping -n 5 127.0.0.1 >nul
)
)
netsh interface show interface name="Local Area Connection" | find /i "disconnected" > NUL 2>&1
IF NOT ERRORLEVEL 1 (
netsh interface show interface name="Wireless Network Connection" | find /i "enabled" > NUL 2>&1
IF ERRORLEVEL 1 (
netsh interface set interface name="Wireless Network Connection" enable > NUL 2>&1
set error=%errorlevel%
ping -n 5 127.0.0.1 >nul
)
)
set /a a+=1
echo.
echo %a%
ping -n 3 127.0.0.1 >nul
if %a% equ 5 goto :eof
goto :loop
:eof
echo.
echo.
set a=
exit /b %error%
Now, you will need to create one task under scheduled tasks. You can save my task xml code in .xml and and then import it to a laptop's task scheduler. Make sure to change the source under Triggers tab to the one that belongs to your specific model:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2014-07-07T09:36:51.4300545</Date>
<Author>%username%</Author>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription><QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='e1cexpress']]]</Select></Query></QueryList></Subscription>
</EventTrigger>
<BootTrigger>
<Enabled>true</Enabled>
<Delay>PT1M</Delay>
</BootTrigger>
<RegistrationTrigger>
<Enabled>true</Enabled>
</RegistrationTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</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>PT1H</ExecutionTimeLimit>
<Priority>7</Priority>
<RestartOnFailure>
<Interval>PT1M</Interval>
<Count>3</Count>
</RestartOnFailure>
</Settings>
<Actions Context="Author">
<Exec>
<Command>%windir%\System32\WifiSwitch.bat</Command>
<WorkingDirectory>%windir%\system32</WorkingDirectory>
</Exec>
</Actions>
</Task>
I wrote something that might help you, I'm working in a scenario where a script wouldn't work and we needed a service that would set itself up and kind of just work, you can find the code here with a packaged installer on the releases page. Good luck.
– sean_m – 2016-04-01T22:59:57.130