If you're on Windows Vista or higher, here is something that may do what you want. For example, this batch file runs a process up to 11 executions, or until 04:17, whichever comes first, waiting one second between each process (to not peg the CPU--if you have file processing you may not need this, or you may actually want to peg the CPU):
@echo off echo Starting Batch... REM Use 'setlocal' so that we can use an environment variable without it leaking out to the caller. setlocal REM Initialize the counter to zero set counter=0 :AGAIN REM Increment the counter set /A counter+=1 echo Processing loop %counter%... REM Wait for one second so as not to peg the CPU timeout /T 1 /NOBREAK>nul REM Check the counter to see if we've done enough iterations--bail out if we have if '%counter%'=='11' goto END REM Check the time to see if the target time has been reached--if not go back and process again FOR /F "TOKENS=1 eol=/ DELIMS=/ " %%A IN ('time /T') DO IF NOT '%%A'=='04:17' goto AGAIN :END REM End the local processing and go back to the main environment endlocal