[SOLVED] How do I make this batch script stop restarting the adapter after 10 restarts?

modemproblem101

Reputable
Jun 3, 2019
19
0
4,510
How do I make this windows batch script stop restarting the adapter after 10 restarts?

Code:
@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
 
Solution
Add variable, that counts restarts.

Code:
@echo off
set /a restartcounter=0
: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")
set /a restartcounter=%restartcounter%+1
if %restartcounter%==10 goto exitloop
goto loop
:exitloop
Add variable, that counts restarts.

Code:
@echo off
set /a restartcounter=0
: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")
set /a restartcounter=%restartcounter%+1
if %restartcounter%==10 goto exitloop
goto loop
:exitloop
 
Solution
@Echo off
SET /A XCOUNT=0
:loop
SET /A XCOUNT+=1
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")
IF "%XCOUNT%" == "10" (
GOTO end
) ELSE (
GOTO loop
)
:end
 
Last edited: