2

In a windows batch file (x.bat), how can I fire a command once every 30 minutes, when the second component of the time is greater than 55?

What I have now is:

:loop
    program.exe
    PING localhost -n 1800 >NUL
goto loop

The problem is that the timing is not precise enough, ie. sec>55 at min%30==29.

Chong Lip Phang
  • 8,755
  • 5
  • 65
  • 100

1 Answers1

1

As mentioned, Task Scheduler is more than capable for this task. It can be run daily, every 30 minutes starting at next hour:59:55

That said, there are ways to script these things. This is not the most robust solution, but it works.

@echo off
:start
for /f %%i in ('powershell Get-Date -Format mm:ss') do (
    if "%%i"=="29:55" program.exe
    if "%%i"=="59:55" program.exe
timeout 1 /nobreak>nul
)
goto start
SomethingDark
  • 13,229
  • 5
  • 50
  • 55
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Apparently a problem with the Task Scheduler is that if the PC restarts, I have to launch the task again. Is there a workaround? Currently, I am placing my batch scripts in shell:startup. – Chong Lip Phang Sep 17 '19 at 07:56
  • well, there is the option of the script I posted if you want to retain the exact 29:55 and 59:55 rule. – Gerhard Sep 17 '19 at 07:58