How do I create a batch file timer to execute / call another batch through out the day Maybe on given times to run but not to run on weekends ? Must run on system times can also be .cmd to run on xp server 2003
9 Answers
For the timer part of your script i highly reccomend using:
echo.
echo Waiting For One Hour...
TIMEOUT /T 3600 /NOBREAK
echo.
echo (Put some Other Processes Here)
echo.
pause >nul
This script waits for 1 hour (3600 seconds) and then continues on with the script and the user cannot press any buttons to bypass the timer (besides CTRL+C).
You can use
Timeout /t 3600 /nobreak >nul
If you don't want to see a countdown on the screen.

- 10,122
- 4
- 20
- 29

- 2,027
- 10
- 38
- 46
-
3Nice. I just found this searching for a simple batch file timer solution - works great, thanks! EDIT: I am using this together with a goto-"loop" to create a simple script which periodically updates my SVN working copy. – alexander.biskop Feb 27 '12 at 15:51
I would use the scheduler (control panel) rather than a cmd line or other application.
Control Panel -> Scheduled tasks

- 20,184
- 24
- 117
- 214
-
1`schtasks` can be used from the command line to manipulate "Scheduled Tasks" – Ken Gentle Nov 18 '08 at 17:29
Below is a batch file that will wait for 1 minute, check the day, and then perform an action. It uses PING.EXE, but requires no files that aren't included with Windows.
@ECHO OFF
:LOOP
ECHO Waiting for 1 minute...
PING -n 60 127.0.0.1>nul
IF %DATE:~0,3%==Mon CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Tue CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Wed CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Thu CALL WootSomeOtherFile.cmd
IF %DATE:~0,3%==Fri CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Sat ECHO Saturday...nothing to do.
IF %DATE:~0,3%==Sun ECHO Sunday...nothing to do.
GOTO LOOP
It could be improved upon in many ways, but it might get you started.

- 19,796
- 7
- 64
- 73
The AT command would do that but that's what the Scheduled Tasks gui is for. Enter "help at" in a cmd window for details.

- 904
- 5
- 5
@echo off
:Start
title timer
color EC
echo Type in an amount of time (Seconds)
set /p time=
color CE
:loop
cls
ping localhost -n 2 >nul
set /a time=%time%-1
echo %time%
if %time% EQU 0 goto Timesup
goto loop
:Timesup
title Time Is Up!
ping localhost -n 2 >nul
ping localhost -n 2 >nul
cls
echo The Time is up!
pause
cls
echo Thank you for using this software.
pause
goto Web
goto Exit
:Web
rem type ur command here
:Exit
Exit
goto Exit
I did it by writing a little C# app that just wakes up to launch periodic tasks -- don't know if it is doable from a batch file without downloading extensions to support a sleep command. (For my purposes the Windows scheduler didn't work because the apps launched had no graphics context available.)

- 2,114
- 12
- 16
-
1why is a graphics context needed to launch from the scheduler? I don't understand why that makes any difference. – Tim May 08 '09 at 17:49
-
In my case I needed to launch an application to run automated tests which did lots of graphics (medical imaging). So they wouldn't run without a graphics context. – Jeff Kotula May 08 '09 at 20:48
@echo off
:Start # seting a ponter
title timer #name the cmd window to "Timer"
echo Type in an amount of time (Seconds)
set /p A= #wating for input from user
set B=1
cls
:loop
ping localhost -n 2 >nul #pinging your self for 1 second
set /A A=A-B #sets the value A - 1
echo %A% # printing A
if %A% EQU 0 goto Timesup #if A = 0 go to ponter Timesup eles loop it
goto loop
:Timesup #ponter Timesup
cls #clear the screen
MSG * /v "time Is Up!" #makes a pop up saying "time Is Up!"
goto Exit #go to exit
:Exit

- 11
- 3
-
buy useing "ping localhost -n 2 >nul" the program "sleeps" for 1 second and this can we use to decrees the value A – nocktok toker Aug 22 '17 at 13:17
better code that doesn't involve ping:
SET COUNTER=0
:loop
SET /a COUNTER=%COUNTER%+1
XCOPY "Server\*" "c:\minecraft\backups\server_backup_%COUNTER%" /i /s
timeout /t 600 /nobreak >nul
goto loop
600 seconds is 10 minutes, however you can set it whatever time you'd like

- 16,432
- 18
- 38
- 60

- 11
- 1
- 2
You could also do this>
@echo off
:loop
set a=60
set /a a-1
if a GTR 1 (
echo %a% minutes remaining...
timeout /t 60 /nobreak >nul
goto a
) else if a LSS 1 goto finished
:finished
::code
::code
::code
pause>nul
Or something like that.

- 80
- 1
- 9