batch file to open 2 progs with time delay

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Hi,

Could anyone please tell me how i write a batch file (.bat) to open 2
programs, the first to open immediately and the second one with a 20
second delay after the first one ??

for example:

I want to open Google Earth first (on my PC it is : C:\Program
Files\Google\Google Earth Pro\googleearth.exe)

Then i want to open another program (Event Manager) 20 seconds after
Google Earth (this program is at C:\Documents and
Settings\Andrew\Desktop\DUMP\EventManager\EventManager.exe on my PC)

I have tried, but i cannot get it to work.


Best Regards,
Andrew
 
You can 'start' a script file from the bat file, and use the argument to
'wait' till it returns. This could be a script that waits 20 seconds before
returning.

---example.bat--
start first.exe
start /wait myscript.vbs
start second.exe
--end file--

--myscript.vbs
wscript.sleep 20000
--end file--
 
Not possible by batch commands, but a very simple script will do this:

; Delay.au3
; Compile with AutoIt 3.x, http://www.autoitscript.com
; Usage in batch: Delay {seconds}

Opt ("TrayIconHide",1)

if $cmd[0] > 0 then
$thisDelay=$cmd[1] * 1000
sleep($thisDelay)
endif
exit
 
Sorry Mark, i don't understand any of that. Just wanted an example that
i could tailor to my own needs. Do you know (based on my needs) what the
exact text file (bat) would look like ?

Best Regards,
Andrew




Mark L. Ferguson:
 
Based on Tom's example, you could do-

start first.exe
echo wscript.sleep 20000 > temp.vbs
start /wait temp.vbs
start second.exe
del temp.vbs

This still uses the WSH, but the bat creates the script on the fly.
 
Sorry Bill, i'm a little thick and still don't get it. Do i just paste
that into a .txt doc and save it as a .bat file then execute it ???,
where do the program links go in ??? Sorry if i appear clueless, but i
am (thats why i posted here !)

Best Regards,
Andrew



Bill Blanton:
 
Copy/paste this into notepad (don't use Word or Wordpad)
and save it as "Andrew.bat"

start "C:\Program Files\Google\Google Earth Pro\googleearth.exe"
echo wscript.sleep 20000 > temp.vbs
start /wait temp.vbs
start "C:\Documents and Settings\Andrew\Desktop\DUMP\EventManager\EventManager.exe"
del temp.vbs
 
Hi Bill,

Thanks for the help.

I have tried what you suggested but nothing happens !!

I run the batch file and 2 little black DOS boxes pop up saying
"C:\Documents and Settings\Andrew\Desktop>"

That's all. Nothing is executed, the 2 DOS boxes just stay there !

Any ideas ??

Best Regards,
Andrew




Blanton:
 
You're right! Sorry, I didn't test it. Forget the bat file, and use
a visual basic script instead. Copy/paste this in notepad and save
it as "Andrew.vbs"


dim oShell
Set oShell=WScript.CreateObject("WScript.Shell")

oShell.Run "calc.exe",1,false
wscript.sleep 20000
oShell.Run "notepad.exe",1,false



If it works, replace "calc.exe" and "notepad.exe" with your complete
programs' paths and names.
 
Ahaaaaa ! - MARVELLOUS Bill !! - that worked ! - Thanks for all your
time and help on this one.

Much Appreciated !

Andy




Bill Blanton:
 
Ah, Bill, sorry - it DID work with your calc.exe and notepad examples.
But it doesn't work in the realworld with the links to my programs !!

Not sure why, because your theory is correct (as it does indeed work
with your examples).

Think i'll give up !!!


Best Regards,
Andrew





Bill Blanton:
 
Further to my last.

I get error message:

Script : C:\Documents and Settings\Andrew\Desktop\Andrew.vbs
Line : 4
Char : 1
Error : The system cannot find the specified file
Code: 80070002
Source : (null)

Cheers,
Andrew



Bill Blanton:
 
Something is mistyped with the path to the executable file. Also make
sure it is wrapped in double quotes.
(e.g.)
"C:\Program Files\Google\Google Earth Pro\googleearth.exe"

Also no line breaks in the line added by the editor.
 
Regards Bill, i'll have a closer look at it, but it does seem to be the
correct path, no broken lines etc. I'm a bit stumped by this !

Cheers,
Andrew


Bill Blanton:
 
Its got to be that. As a test, copy/paste the program path into the Start > Run...
dialog box. If it doesn't run it's incorrect.
 
Hi Bill,

I have tried that and it does run in the Start - Run command !! - just
not in the vbs file !! - that's the weird bit !!!!

Cheers,
Andrew



Bill Blanton:
 
How about sending me the file as an attachment, so I can look at it.
Rename it Andrew.txt so it doesn't get flagged and deleted along the
way.
 
Cheers Bill. Will do, what's the e-mail add to send it to ?

I hope any solutions found are posted to this thread. I'd also like to
start a couple of apps using the vbs script and haven't got it to work
here either, although the calc and notepad example works fine.
 
Back
Top