# Is there a timer command in DOS?



## flyboy320

I have a program running in dos that I would like to reboot once a day around 3:00am. I have a reboot.exe file that will do it for me, but I need a way to execute this at the prescribed time/interval.

Is there a way I could put this command in my autoexec.bat file and have it run reboot.exe after a certain amount of time has passed, or at a certain clock time?


----------



## Rockn

You could write a simple timer app in Basic...batch files aren't meant to do this sort of thing. There are also tons of freeware timer applications on the net.


----------



## flyboy320

Thanks I'll look around.......


----------



## Cosmic

There is no Timer function as part of DOS.

You didn't say if you have the source code for the running program. If you do it is a piece of cake to add a TIMER check feature and reboot the machine within the running program at a time of your choosing. You didn't say if you have any programming abilities. Sounds like not, or you wouldn't be asking this question.

If you do not have the source code, the best way is to get a TSR utility running in background to do the job. This TSR utility would load via your normal boot sequence. It would continually check the TIMER and execute the reboot at your specified time. A very slick neat tailored solution. One thing to think about, you probably also need to set a flag, so the TSR knows the reboot has occured for a particular day.

I would do it such that control of the reboot time is set in a stored text file on the hard drive that the TSR checks to get its set point when loading up on the boot. Also would check to see if it already had rebooted for the day. Probably need to lock out any potential pumping or nasty type loops that can occur. 

Flag can also be in the text file and reset at midnight each day by the TSR. Or you could store it in the IAC if you wanted to get real slick. Therefore only one reboot is sure to occur each day. Changing your setpoint would be very easy by just using any ASCII word processor to rewrite the setpoint value in the stored text file at any time of your choosing.

You need a tailored function type TSR written exactly for the job. Could be at a particular time, elapsed interval or whatever your lil heart desires. Couple ways to get one. 

1. Write it yourself. PowerBasic language has the ability to easily make this type TSR running under DOS.

2. Check the PowerBasic programming websites and see if something like this already exists. These folks deal in source code, so anything found can be easily modified.

3. Beg someone at the PowerBasic programming websites to write you one or modify whatever found. Folks love these type requests.

4. In a real pinch, I might write you one. Don't know what month that might be.


----------



## mole

ping -n {x} 127.0.0.1 >nul

where x is the number of counts. If you make {x} = 10 it will be ca. 10 seconds.

mole


----------



## Guest

There's no included timer command in DOS. But like everyone before me said, you can goto a place like download.com and search for that program as I am sure there are many of those types os apps availible for free.

HexStar


----------



## mole

You can make a timer as I have shown.

mole


----------



## Cosmic

This original post was incomplete. This points up the fact, that under DOS this problem is not easy, if you want to do it outside of the running program source code environment. Original poster Flyboy left us in the dark as to exact requirements.

If you have the source code, couple lines of code, not a problem.

If you want to attempt this exercise around the horn. BAT Files or whatever, TSR utility, or whatever you may have to bolt the requirement on to another compiled running DOS independent program, lots of luck.

Not really that easy to solve the original problem, never was, if you can not embed the solution in the running program source code.

You are faced with the problem of running an external requirement outside of the main running DOS program which is not a multi-tasking environment. The number of successful problem free examples is small.

You can do it exactly with a very well tailored TSR that does the TIMER check function, that continues to run in background and calls an On-Event task to interrupt the main program based on a large number of criteria. Not as simple as it sounds, unless you can embed in the source code of the main program.

You can do it under PowerBASIC, maybe under C, maybe under MASM, maybe under some very, very tricky BAT file scenario. The trick is going to be get it easy, small and problem free under any scenario. PowerBASIC can be done relatively easy but will not be a Tiny Model. Might work, might not, haven't attempted it.

The proof will be writing and posting a complete working program that can operate totally outside of any other independent running DOS program. I would be interested in seeing that; whatever method you might choose to present it as a complete solution. Please walk me thru each step.

Could definitely take your expertise to school for use in a number areas; I am interested in writing very large DOS programs where psuedo multi-tasking is desirable. Please be exact as to methodology and coding. Simple and foolproof is a big plus.


----------



## Cosmic

Duh, after mulling over the original problem.

The simple solution is a hardware one. Use a plug in timer to turn off power to the PC at the desired time. When it turns back on do an auto-boot sequence where everything required loads and runs.

The very cheap common timers probably have a minimum Off internal in the several minutes range. The solid state ones might be more suitable if the Off Internal is critical.

Or as Murphy's Law might state:

All first solutions are wrong ...... The path of greatest resistance is the one usually taken


----------



## Rockn

NOOOO....this is not a good way to shut down your PC and you will inevitabley screw up your OS doing it that way. If you have Win98 or better you can do it even easier for a shutdown. There is a very...very simple way to do this. Wrote back with your OS and I will show you how it's done using nothing more than Windoze funtionality.


----------



## bobpaul

No, it's not a good way to restart windows, linux, mac os, or unix by disconnecting the power, but for the most part, dos doesn't care. Actually, that is the only way to shutdown a dos machine, so it won't matter. In Windows it isn't even that big of a deal. But you're right, the prefered method to shutdown windows is with the proper command and one could use the Windows Scheduling agent in Win98+ or download a scheduling App for Win95 to shut the system down properly at a specified time. Since he said in the initial post that he's using dos, though, there is no scheduling agent.

A timer on the power supply will be fine. Just make sure that if you have an ATX power supply the bios set to turn the computer on after a power failure. Other wise the system will remain off. If you have an AT power supply, this, of course, will not be a problem.


----------



## bobpaul

Also, run a search for doat.zip on the internet

This program can be placed in the autoexec.bat file and will run a program at a specified time, ie it can run reboot.exe everyday at 3am.

ex: at 3:00 c:\reboot.exe


----------



## top_gizmo

Ok, we know it is not good to reboot your computer like this...

So, the problem is that you want to kill that application at 3:00

Goto, www.hiddensoft.com and get a copy of Autoit 2.64

This will let you write a easy script to kill the application via Task Manager instead of rebooting like this.

Alternativly, you could write a shutdown or reboot script also.


----------



## bobpaul

But most important is that he's using Dos, not windows. That's why he was asking about bat files. Read the origional post


----------



## prakka

Wouldn't it be just as easy to make an program (asdf.bat) with the IF command that checks for the local time with a specific time (in this case 03:00 am). And when that is, you run your reboot.bat thingy. You will also need to put asdf.bat in the autoexec configure file to auto start-up when the pc starts.
It isn't really that hard, just look on a search engine for batch commands.


----------



## bobpaul

prakka said:


> Wouldn't it be just as easy to make an program (asdf.bat) with the IF command that checks for the local time with a specific time (in this case 03:00 am). And when that is, you run your reboot.bat thingy. You will also need to put asdf.bat in the autoexec configure file to auto start-up when the pc starts.
> It isn't really that hard, just look on a search engine for batch commands.


If it's so easy and you've already found the commands, why didn't you post what he needs?

Because you can't do this entirely in bat files. Your easy program (asdf.bat) would have to be a compiled app something like checktime.exe

PROVIDED that your homemade checktime.exe returned 0 from the main() function when the time is correct and 0 when it's not AND that it accepts the time as an argument, you could do something like this (syntax might be off, it's been a while)



Code:


@echo off

:start
c:\checktime.exe 03:00
IF ERRORLEVEL==1 THEN GOTO start
IF ERRORLEVEL==0 THEN GOTO run

:run
REM put the command you want to run at 3 am here.

If you saved the above batch file as threeam.bat and put the following in your autoexec.bat it should run everynight:


Code:


call threeam.bat

However, this is all dependant on the above program. There is no possible way to parse the output of the date command or anything like that using BAT files alone. Bash is more useful in that regard, but remember, DOS was origionally QDOS before MS bought it to supply IBM: Quick and Dirty Operating System. The IF statement is very limited.

An alternative to the above would be to compile a program that saves the current time to the environment variable %CURTIME% in a specific format Then you could do something like


Code:


@echo off

:start
c:\checktime.exe
IF "%CURTIME%=="03:00" THEN GOTO run
goto start

:run
REM Put the commands you want to run here

But this again requires compiled code checktime.exe.


----------



## awalker0878

here is old symantec utility which contaion the ability to "wait" before executing

please note make sure you have a liscense for norton systemworks 200x before using


----------



## Squashman

Nothing like resurrecting an old thread.


----------



## Cosmic

Squashman said:


> Nothing like resurrecting an old thread.


Yeah ......., I just love an answer in search of a question. This could go on for a very long time. We may even need some sort of Super Timer just to clock the answer frequency.

I wonder if the fellow ever got it to work.

I gave the best approaches before. If you are technically challenged, the application is a pure DOS machine just use the plug-in wall timer to turn the machine off. No that will not hurt anything. This assumes you are not running a DOS program on a Windows machine.

The best solution is a simple BASIC complied program written in Power BASIC as a TSR. Attached is some code how to even make it a precision timer. This would be a very small TSR EXE that you can load on boot. For Time of Day it is even more simple. Just check the time and compare against setpoint.

Couple other ways. There was an old DOS utility called DoubleDOS that would allow two programs to run at the same time. Was a bit buggy but you could set the size of the RAM drive very exact. Will allow a crude method to be used.

Another solution is to use a memory manager. In theory a program can use installed memory beyond the 640K barrier. Few good working examples. Most solutions use up way to much conventional memory to do something that "Saves" memory.

Here is a snip from a manual I wrote on building DOS precision timers:

This simple two line timer will do the job.

StartTime = TIMER
WHILE TIMER - StartTime < 5 : Wend

The < 5 is the setpoint, in this case 5 seconds. The first line gets the
onboard TIMER value and makes StartTime equal to that value.

The second line then tests the ongoing timer value against that value
selected in the first line and when the onboard TIMER is greater than the
first selected value it continues on in the progam.

This simple method has a problem if the TIMER is reset to zero. This happens
at midnight each night and any time your computer is rebooted. To make the
situation always be true, add this to the timer.

StartTime = TIMER
DO WHILE TIMER - StartTime <5
IF TIMER <5 THEN EXIT DO
LOOP

The setpoint can be just about any value you choose. For a one minute delay
make the value 60. Fractional seconds values can be used, like 1.25 seconds.
The setpoint can be a variable name and its value determined else where in
the program.

Note that in the above timer to take care of the situation when the timer
reset to zero, like at midnight, we jump out of the timer loop. Depending on
the situation this might not be satisfactory. If the setpoint if a long one,
you would want to determine the jump condition because of a reset, determine
the time elasped, determine the time still to go and start another corrected
timer. The best way to do that is exit to another procedure to make the
correction.

By modifying this basic timer with other conditional steps just about any
situation involving time can be addressed.

Now somebody has to dream up a way to get a Chinese water clock into the scheme.


----------

