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

Jun 3, 2019
5
0
10
0
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
 
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
 

AllanGH

Commendable
Mar 10, 2019
1,704
320
1,640
48
@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:

ASK THE COMMUNITY

TRENDING THREADS