batch file to open 2 progs with time delay

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
 
M

Mark L. Ferguson

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--
 
G

Guest

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
 
A

Andy

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:
 
B

Bill Blanton

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.
 
A

Andy

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:
 
B

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
 
A

Andy

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:
 
B

Bill 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.
 
A

Andy

Ahaaaaa ! - MARVELLOUS Bill !! - that worked ! - Thanks for all your
time and help on this one.

Much Appreciated !

Andy




Bill Blanton:
 
A

Andy

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:
 
A

Andy

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:
 
B

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.
 
A

Andy

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:
 
B

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.
 
A

Andy

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:
 
B

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.
 
A

Andy

Cheers Bill. Will do, what's the e-mail add to send it to ?

Best Regards
Andy



Bill Blanton:
 
Z

Zilbandy

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.
 
A

Andy

Thanks, yeah i'll post back here if i can get this solved !

Best Regards,
Andrew


Zilbandy:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top