We've got code in productions, that checks file attributes (result of check.bat file1.bin returns 0 or 1) and restart user processes if necessary (if returned 1, then restart process). Code is working fine, but I just wanted to ask is there a way to improve it with FOR loop, since we really do the same thing every cycle, but with +1 to username, task name and filename
@echo off
:cycle1
FOR /F "tokens=* USEBACKQ" %%F IN (`check.bat file1.bin`) DO (SET var=%%F )
if %var% == 1 (taskkill /f /fi "USERNAME eq user1" & SCHTASKS /RUN /TN "task1")
goto cycle2
:cycle2
FOR /F "tokens=* USEBACKQ" %%F IN (`check.bat file2.bin`) DO (SET var=%%F )
if %var% == 1 (taskkill /f /fi "USERNAME eq user2" & SCHTASKS /RUN /TN "task2")
goto cycle3
:cycle3
FOR /F "tokens=* USEBACKQ" %%F IN (`check.bat file3.bin`) DO (SET var=%%F )
if %var% == 1 (taskkill /f /fi "USERNAME eq user3" & SCHTASKS /RUN /TN "task3")
goto eof
:eof
exit /b 0