Link to home
Start Free TrialLog in
Avatar of newbie46
newbie46

asked on

Is it possible to set a 7 hour delay in a batch file to have the same effect as scheduling a task in Task Scheduler to run at midnight?

I have a batch file which runs a macro in an Access 2007 database. It takes hours for the Access code to run, so I want it to run overnight:

Echo Off
"C:\Program Files\Microsoft Office\Office12\msaccess.exe" "c:\users\me\Documents\databasename.accdb" /x macroname
Exit

My goal is to schedule a task in the task scheduler so that this macro will run at midnight. I am just looking for a plan B in case I don't have permissions to set up a task and there are issues with IT doing this for me. Is it possible to put a 7 hour delay in the batch file? In this way, we could run the batch file at 5pm and it wouldn't run the Access macro until midnight.

I see information on the internet concerning setting a delay for up to 99 seconds. Is it possible to set a delay for 7 hours?

Thanks.
SOLUTION
Avatar of yobri
yobri
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
^ In the first sentence, certain files was meant to say certain processes.
SOLUTION
Avatar of Tim Bouscal
Tim Bouscal
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here it is

While it runs, look at the title bar.

Cheers,
Rene

 
@ECHO OFF

ECHO STARTED AT: %date% %time%
SET CountDownHours=7

:HOME

FOR /L %%A IN (%CountDownHours%,-1,1) DO (
	FOR /L %%B IN (60,-1,1) DO (
		FOR /L %%C IN (60,-1,1) DO (
			TITLE COUNT DOWN: HOUR:%%A MIN:%%B SEC:%%C
			CHOICE /D Y /T 1 >NUL

		)
	)
)

ECHO COMPLETED AT: %date% %time%
ECHO.
PAUSE

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Inspired by bp's script, I did this one for fun

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

REM THIS IS ASSUMING THAT THE COUNT DOWN WILL FINNISH THE SAME DAY
REM W=WAIT T=TARGET EX.: WHour THour

SET WHour=0
SET WMin=1
SET WSec=10

REM SETTING UP TARGET TIME
FOR /F "tokens=1-3 delims=:, " %%A IN ("%TIME%") DO (
	SET /a THour+=%%A + %WHour%
	SET /a TMin+=%%B + %WMin%
	SET /a TSec+=%%C + %WSec%

	IF !TSec! GTR 60 (
		SET /a TMin+=1
		SET /A TSec-=60
	)
	
	IF !TMin! GTR 60 (
		SET /a THour+=1
		SET /A TMin-=60
	)
	
	IF !THour! GTR 24 (
		ECHO ERROR
		PAUSE
		EXIT
	)
)

REM WAITING FOR THE TARGET TIME TO COME
:HOME
CHOICE /D Y /T 1 >NUL
ECHO %time% | Findstr -i "!THour!:!TMin!:!TSec!"
IF !errorlevel! NEQ 1 GOTO Home

Echo Done

PAUSE

Open in new window

By the way, I know it's not working. Just felt like sharing my idea.
I'd like to develop this idea so I'll create a new post
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial