Windows 10

How to Run Batch File Automatically Every X Minutes

In this tutorial, we’ll explore two methods to automatically run a batch file every X seconds or minutes using native Windows command-line utilities. This is useful for scenarios like scheduled polling, automated checks, data sync operations, or periodic task execution—without needing Task Scheduler or third-party tools.
 

🔁 Example 1: Loop Execution with timeout (Recommended)

The timeout command is a built-in utility that pauses the execution for a given number of seconds, making it ideal for implementing simple timers.

@echo off
set INTERVAL=10

:loop
REM Place your commands here (e.g., call another .bat file)
echo Running task...
timeout /t %INTERVAL% >nul
goto loop

🔍 Explanation:

  • set INTERVAL=10: Sets the delay interval to 10 seconds.
  • timeout /t %INTERVAL% >nul: Waits silently for the specified time.
  • goto loop: Repeats the process indefinitely.

✅ Output:
This will repeat the block of code every 10 seconds until the window is manually closed.
 
 

🧪 Example 2: Using ping as a Delay Mechanism

The ping command can be repurposed as a delay by pinging the loopback address (127.0.0.1) multiple times.

@echo off

:loop
echo Running task...
REM Your batch logic goes here
ping -n 6 127.0.0.1 >nul
goto loop

🔍 Explanation:

  • ping -n 6 sends 5 echo requests and adds about a 5-second delay.
  • Use -n N+1 where N is the number of seconds (since the first ping occurs immediately).
  • >nul suppresses output.
📌 Note: This is a workaround and not as precise or efficient as timeout, but it works on older systems where timeout is not available (e.g., Windows XP).

 
⚠️ Considerations:

  • This method runs indefinitely. To stop it, the user must manually close the command prompt window.
  • If you’re scheduling production tasks, consider using Task Scheduler or PowerShell scheduled jobs for reliability and log management.

 

🧠 Pro Tip: Calling External Scripts

You can call external batch files or scripts inside the loop:

call myscript.bat

Or use conditional logic based on file existence, time, or network state.
 

✅ Summary

To run a batch script repeatedly at fixed intervals, use timeout or ping as delay mechanisms. Both methods provide lightweight scheduling within the constraints of batch scripting, without needing elevated privileges or scheduled tasks.
 

🚀 Boost your productivity with the best AI toolsTry them

 

One thought on “How to Run Batch File Automatically Every X Minutes

  • Developer

    I need a window terminal command for repeating a command after every hour . Please help.
    Thanks

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *