Computing.Net > Forums > Disk Operating System > How can you delay execution of bat

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How can you delay execution of bat

Reply to Message Icon

Name: sekirt
Date: August 19, 2003 at 10:38:57 Pacific
OS: Windows 98se
CPU/Ram: pentium
Comment:

Here is what I would like to work out:
1) Load a batch file in autoexec on boot up.
(no problem doing this).
2) While having it running, delay any action for 10 minutes. (this is where I need help, I don't know how to delay it for a length of time).

I want it to delete various files 10 minutes after I boot-up, unless I change my mind. If I should change my mind, I would ctrl-break the batch file. If I don't change my mind, it would continue to work after 10 min and delete the files.

I don't need any keypress to disable it or anything visible. All of it can run in the background under windows.

sekirt




Sponsored Link
Ads by Google

Response Number 1
Name: borelli34
Date: August 19, 2003 at 10:53:08 Pacific
Reply:

=================================================
Ok, the thing is that if a batch file is paused or locked up in a delay then the system will not continue to boot until the batch file completes. You could run a batch file after booting into windows but this takes putting it in the startup menu or the registry and there would be a visible window open for this process. I've written device drivers to do things like this but it then requires that this driver continue running even after it has completed its goal under 98 because other drivers have been statically loaded after it and windows would not be aware of its unloading. If you have more specific information that might help then post it here or you can even email me at borelli34@hotmail.com. Maybe we could come up with something or at least a comprimise that will work for you.

borelli34


0

Response Number 2
Name: sekirt
Date: August 19, 2003 at 15:21:37 Pacific
Reply:

Thanks.
Just never occurred to me.
sekirt



0

Response Number 3
Name: Brian HANLON
Date: August 21, 2003 at 08:43:06 Pacific
Reply:

Okay, it isn't elegant, but it does the job. Albiet with a minimised button on the taskbar - but I gather from your first post, that it is for your own use, and not a Client Security issue.
As has already been mentioned in a previous post, this would have to be started from the STARTUP Menu, but at least that allows for the timing to take be reasonably OK even if you are called to the 'phone while the system is booting, and you don't log in for half an hour or so!

Comments have been left intact, because it is still under 4Kb, which means that it is less than one cluster.
Retaining the comments means that in 3 months time, you can quickly work out what is going on, courtesy of those comments.

To keep this minimised, create a PIF (Shortcut) and edit the Properties of the PIF so that it runs MINIMISED.

First of all, create a BATchfile which will actually perform the deletions you require. For example:

KILLER.BAT

@ECHO OFF
IF EXIST C:\HOLD4AWHILE\OLDFILE.001 DELTREE /Y C:\HOLD4AWHILE\OLDFILE.001>NUL
IF EXIST C:\HOLD4AWHILE\OLDFILE.002 DELTREE /Y C:\HOLD4AWHILE\OLDFILE.002>NUL
IF EXIST C:\HOLD4AWHILE\OLDFILE.003 DELTREE /Y C:\HOLD4AWHILE\OLDFILE.003>NUL
IF EXIST C:\HOLD4AWHILE\OLDFILE.004 DELTREE /Y C:\HOLD4AWHILE\OLDFILE.004>NUL

And you would use:
DELAY.BAT 0,9,5,5,KILLER.BAT
to do your job.

Or, if you have SHORT PATH/FILENAMEs then:

KILLER2.BAT

@ECHO OFF
IF %1!==! GOTO DONE
:LOOP
IF EXIST "%1" DELTREE /Y "%1">NUL
SHIFT
IF NOT %1!==! GOTO LOOP
:DONE

Then if KILLER2.BAT is in the same folder as the OLDFILE series, and DELAY.BAT is also in the same folder, you could then use:
DELAY.BAT 0,9,5,5,KILLER2.BAT,OLDFILE.001,OLDFILE.002,OLDFILE.003,OLDFILE.004
to achieve the same result

The >NUL just avoids a window full of clutter telling you that it has DELETED OLDFILE.001 etc.
I suggest using the (Highly dangerous) DELTREE /Y filename.ext>nul command, as it has a LOT of very useful power for the BATch Programmer. Run DELTREE /? to check its use, and play around with the command WITHOUT the /Y parameter until you become confident with this very useful replacement for the old DEL or ERASE.
Just DO NOT AIM DELTREE at ANY part of your WINDOWS Directory branches or you'll DESTROY THE SYSTEM - ESPECIALLY WITH THE /Y !!!

I find that this modular approach leaves you with little Building Blocks which you can utilise for all those odd BATches which you meant to get around to one day.

Each line indented two spaces to highlight line-wraps.

----------CUT----------
@echo off
::
:: DELAY.BAT
:: A BATch file by Baldy Brian to control variable long delays
::
:: Designed for and Tested under Win98SE
::
::
:: Call is: delay minutes TENS, minutes UNITS, SECONDS, App [0-8 Params]
::
:: DELAY.BAT 0,9,5,5,"C:\MY BATCH FILES\KILLER.BAT",p1,p2,p3,p4,p5,p6,p7,p8
:: allows 5 Seconds for internal overhead time - adjust to suit.
:: Waits for 09:55 and executes KILLER.BAT with (Optional) Parameters p1-p8
::
:: Note that the extension MUST be specified! ie NOTEPAD.exe
::
:: QUOTE any longfilenames or paths_with_spaces
::
IF EXIST %TEMP%\WAIT$10M.BAT.BAT DELTREE /Y %TEMP%\WAIT$10M.BAT>NUL
IF EXIST %TEMP%\WAIT$01M.BAT.BAT DELTREE /Y %TEMP%\WAIT$01M.BAT>NUL
::
:: Clear the way for our 10 and 1 Minute batches
::
ECHO > %TEMP%\WAIT$10M.BAT @FOR %%%X IN (1;2;3;4;5;6;7;8;9;0) DO CHOICE /N /C:`~ /T:`,60
::
:: WRITE WAIT$10M.BAT in %temp%\
:: This is probably C:\WINDOWS\TEMP
:: each CHOICE command will WAIT for 60 Seconds.
:: Tilde/backquote cancels wait, (shortens delay)
:: any other key forces HALT until tilde/backquote pressed.
::
:: %TEMP%\WAIT$10M.BAT.bat now holds 10 * 60 second delays
:: each delay may be aborted via the Tilde-backquote key
:: or the whole BATCH aborted via the Ctrl-C combination.
:: Each call to %TEMP%\WAIT$10M.BAT will perform 10 * 60Second pauses.
::
ECHO > %TEMP%\WAIT$01M.BAT @CHOICE /N /C:`~ /T:`,60
::
:: WRITE WAIT$01M.BAT in %temp%\
:: CHOICE command will WAIT for 60 Seconds.
:: Each call to %TEMP%\WAIT$01M.BAT will perform 1 * 60Second pause.
::
:: Note the redirect PRECEDING the echo command - WON'T WORK
::
:: The seconds can be handled internally
::
:: Some basic error checking:
::
SET RUN=RUN
::
:: Set the RUN_or_DIE switch
::
FOR %%X IN (0,1,2,3,4,5,6,7,8,9) DO IF %%X* == %1* GOTO OK10M
:NOTOK10M
ECHO CANNOT DELAY {%1} x 10 Minutes
SET RUN=DIE
:OK10M
::
FOR %%X IN (0,1,2,3,4,5,6,7,8,9) DO IF %%X* == %2* GOTO OK1M
:NOTOK1M
ECHO CANNOT DELAY {%2} Minutes
SET RUN=DIE
:OK1M
::
FOR %%X IN (0,1,2,3,4,5,6,7,8,9) DO IF %%X* == %3* GOTO OK10S
:NOTOK10S
ECHO CANNOT DELAY {%3} x 10 Seconds
SET RUN=DIE
:OK10S
::
FOR %%X IN (0,1,2,3,4,5,6,7,8,9) DO IF %%X* == %4* GOTO OK1S
:NOTOK1S
ECHO CANNOT DELAY {%4} Seconds
SET RUN=DIE
:OK1S
::
IF EXIST "%5" GOTO OK2%RUN%
ECHO CANNOT RUN {%5} - NOT FOUND
GOTO OK2DIE
::
:OK2RUN
::
GOTO T%1
:T9
CALL %TEMP%\WAIT$10M.BAT
:T8
CALL %TEMP%\WAIT$10M.BAT
:T7
CALL %TEMP%\WAIT$10M.BAT
:T6
CALL %TEMP%\WAIT$10M.BAT
:T5
CALL %TEMP%\WAIT$10M.BAT
:T4
CALL %TEMP%\WAIT$10M.BAT
:T3
CALL %TEMP%\WAIT$10M.BAT
:T2
CALL %TEMP%\WAIT$10M.BAT
:T1
CALL %TEMP%\WAIT$10M.BAT
:T0
:: Thats the TENS of minutes done with!
::
GOTO U%2
::
:U9
CALL %TEMP%\WAIT$01M.BAT
:U8
CALL %TEMP%\WAIT$01M.BAT
:U7
CALL %TEMP%\WAIT$01M.BAT
:U6
CALL %TEMP%\WAIT$01M.BAT
:U5
CALL %TEMP%\WAIT$01M.BAT
:U4
CALL %TEMP%\WAIT$01M.BAT
:U3
CALL %TEMP%\WAIT$01M.BAT
:U2
CALL %TEMP%\WAIT$01M.BAT
:U1
CALL %TEMP%\WAIT$01M.BAT
:U0
:: Thats the UNITS of minutes done with!
::
:: Warn in last seconds
::
START /m C:\WINDOWS\MEDIA\DING.WAV
::
:: START [options] program [arg...]
:: START [options] document.ext
::
:: /m[inimized] Run prgm minimized (in the background).
:: /max[imized] Run prgm maximized (in the foreground).
:: /r[estored] Run prgm restored (in the foreground). [default]
:: /w[ait] Does not return until the other program exits.
::
::
IF %3%4! == 00! GOTO ZEROS
:: Avoid the zero = infinite wait.
::
CHOICE /N /C:`~ /T:`,%3%4
::
:ZEROS
::
:: Thats the SECONDS done with! NOW DO THE JOB!
::
SHIFT
SHIFT
SHIFT
SHIFT
:: %5 to %4, %4 to %3, %3 to %2, %2 to %1
::
:: So we can have a BAT/EXE name and up to 8 Parameters
::
START /r %1 %2 %3 %4 %5 %6 %7 %8 %9
::
:OK2DIE
::
IF EXIST %TEMP%\WAIT$10M.BAT.BAT DELTREE /Y %TEMP%\WAIT$10M.BAT>nul
IF EXIST %TEMP%\WAIT$01M.BAT.BAT DELTREE /Y %TEMP%\WAIT$01M.BAT>nul
SET RUN=
::
:: Cleans up now we have finished
::
----------CUT----------

I've been running this BATchfile for about 10 years, in various incarnations, and this particular version has been in use for about 30 Months.
It totally avoids the use of third party software, and is reasonably accurate with its timing.

Hope it helps you out with your problem, or gives you a clue towards writing a BATchfile of your own.

Baldy Brian - AussieozXpress-com-au
NO CAPS, dots in the usual places, you know what the "at" becomes ;>P


0

Response Number 4
Name: sekirt
Date: August 21, 2003 at 10:54:39 Pacific
Reply:

Whew!
Sounds good Brian and I am going to try it out. Thank you very much.

sekirt


0

Response Number 5
Name: Brian HANLON
Date: August 23, 2003 at 08:43:58 Pacific
Reply:

Just watch out for where the Brain-dead forms script has wrapped some lines
Most are pretty obvious, but if you have hassles, mail me & I'll see what I can do.
Baldy


0

Related Posts

See More



Response Number 6
Name: Brian HANLON
Date: August 23, 2003 at 09:20:18 Pacific
Reply:

sekirt:

It might save some sweat to also have a look at:

Extract from URL: http://members.cox.net/dos/batch02.htm#sleep


SLEEP- Batch util sleeps until event occurrence.


A very flexible command line tool for scheduling events; intended for batch files. "The possible events are: FOR a length of time, TILL a certain time, a question ASKed of the user, certain FILESPECS appear or disappear, the UPS is active, or a SCHEDuled event. Commands can be combined. Sleep is DOS, DesqView (uses DV System Memory), OS/2, and Windows aware.
Sleep will accept an indirect command file. Multiple lines can be used and command files can be nested. The resulting command line must be under 16K.
Sleep takes up to 100 filespecs, with paths and wildcards. Sleep will exit when any of these filespecs is created (+) or deleted (-). If also prefixed by "&", the conditions for those filespecs are AND'ed rather than OR'ed.
Serial and parallel port monitoring: Sleep outputs a byte to the port's control register, then monitors the port's status register, looking for the presence (+) or absence (-) of a bit or bits.
Scheduled events can stored in a file which contains one line per event. Sleep returns the error level of an event when it occurs.
Sleep can also be called to return an error level based on the date or time.
The cursor keys can be used to modify time remaining."

Usage:
INDIRECT COMMAND FILE.Sleep "@"
FOR syntax............Sleep for [[hh":"]mm":"]ss
TILL syntax...........Sleep till [[hh":"]mm":"]ss
ASK syntax............Sleep ask ''
FILESPECS syntax......Sleep ["&"]"+"|"-" ...
PAR and SER syntax....Sleep par|ser "+" "-"
SCHED syntax..........Sleep sched

No documentation- type SLEEP /? for extended help screens. Author: John R. Souvestre (1997)

download sleep_47.zip (33K) from URL: ftp://ftp.sac.sk/pub/sac/utiltask/sleep_47.zip

Might be easier to implement and also can check/wait for appearance of a particular file. Possibly a useful trigger for your needs.
Baldy.


0

Response Number 7
Name: sekirt
Date: August 23, 2003 at 19:16:30 Pacific
Reply:

Brian,

I downloaded the Sleep program you suggested. I also have a different one called Sleep. I will compare the 2 programs. I also have one called Wait.

You have supplied plenty of things to consider, thanks again for all your input.

sekirt


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: How can you delay execution of bat

How can you hide the DOS command window www.computing.net/answers/dos/how-can-you-hide-the-dos-command-window-/5607.html

ask the user to enter a parameter during the execution of a .bat www.computing.net/answers/dos/ask-the-user-to-enter-a-parameter-during-the-execution-of-a-bat/2791.html

How can i write from bat file www.computing.net/answers/dos/how-can-i-write-from-bat-file/6434.html