@echo off
setlocal enabledelayedexpansion
set "_batch_dir=C:\some\Directory\target"
set "_KeyRunOnce=HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
if not "%~1" == "" (set "_skp=skip=%~1" && set "_count=%~1")else set "_count=1"
for /f %%i in ('dir /b /s /aa "%_batch_dir%\*.bat" ^| find /v /c ""')do set /a "_total=%%~i"
for /f "%_skp% delims=" %%i in ('2^>nul where.exe /r "%_batch_dir%" "*.bat"')do if !_count! lss !_total! =;(
reg add "%_KeyRunOnce%" /v "%~n0" /d "\"%~f0\" \"!_count!\"" /f && set /a "_count+=1" );= 1>nul 2>&1 & call "%%~i"
1>nul 2>&1 reg delete "%_KeyRunOnce%" /v "%~n0" /f & endlocal
1. Start by counting the total of your bat files to run
2. Obtained the total, check if the current execution is the initial, interval or last
3. Add a counter and through that, execute the value of the counter and use that indicator for the relevant continuity execution.
4. Define which bat to start, continue and end with the argument and RunOnce
key suggested by @tabby.sl
5. Replace For /R
to For /F
and use counter as argument in RunOnce, and use argument as skip
in your For /F skip=Argument
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
and the value of that registry entry should be changed to the second batch file location (so on applies to the second batch file too)