0

How do I make this windows batch script stop restarting the adapter after 10 restarts?

@echo off

:loop

timeout /t 8

echo Checking...

ping -n 1 192.168.1.1|Findstr /I /C:"timed" /C:"unreachable" /C:"find host" /C:"failure"

if %errorlevel%==0 (echo Restarting...

netsh interface set interface name="Local Area Connection" admin="disabled"

netsh interface set interface name="Local Area Connection" admin="enabled")

goto loop

0

Got it.

@echo off
set /a restarts=1
:loop
timeout /t 6
echo Checking...
ping -n 1 192.168.1.1 | findstr /i /c:"timed" /c:"unreachable" /c:"find host" /c:"failure"
if %errorlevel%==0 (echo Restart attempt #%restarts%...
netsh interface set interface name="Local Area Connection" admin="disabled"
netsh interface set interface name="Local Area Connection" admin="enabled"
set /a restarts+=1)
if %restarts%==6 exit
goto loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.