Go Back   TechArena Community > Technical Support > Computer Help > Windows XP > Windows XP Support
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



batch file to open 2 progs with time delay

Windows XP Support


Reply
 
Thread Tools Search this Thread
  #1  
Old 17-09-2007
Andy
 
Posts: n/a
batch file to open 2 progs with time delay

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.
Reply With Quote
  #2  
Old 18-09-2007
Mark L. Ferguson
 
Posts: n/a
Re: batch file to open 2 progs with time delay

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--
Reply With Quote
  #3  
Old 18-09-2007
Anteaus
 
Posts: n/a
RE: batch file to open 2 progs with time delay

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


Reply With Quote
  #4  
Old 18-09-2007
Andy
 
Posts: n/a
Re: batch file to open 2 progs with time delay

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 ?
Reply With Quote
  #5  
Old 18-09-2007
Bill Blanton
 
Posts: n/a
Re: batch file to open 2 progs with time delay

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.
Reply With Quote
  #6  
Old 18-09-2007
Andy
 
Posts: n/a
Re: batch file to open 2 progs with time delay

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,
Reply With Quote
  #7  
Old 18-09-2007
Bill Blanton
 
Posts: n/a
Re: batch file to open 2 progs with time delay

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
Reply With Quote
  #8  
Old 18-09-2007
Andy
 
Posts: n/a
Re: batch file to open 2 progs with time delay

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 ??
Reply With Quote
  #9  
Old 19-09-2007
Bill Blanton
 
Posts: n/a
Re: batch file to open 2 progs with time delay

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.
Reply With Quote
  #10  
Old 19-09-2007
Andy
 
Posts: n/a
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)
Reply With Quote
  #11  
Old 19-09-2007
Bill Blanton
 
Posts: n/a
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.
Reply With Quote
  #12  
Old 17-12-2009
Danbo342
 
Posts: n/a
Hey Andrew, this is my first night of writing batch files and was actually trying to figure out the google earth issue when I found this post. In the mean time I ended up figuring out a workaround on my own. I'm not sure about the event manager since I have vista 64 but I tested this out using event viewer.
My only experience is about 23 minutes and this will work 100% so not sure but these guys look like they may be joking with you.

Anyway, this is a "Bat" file and works fine. The only problem I had was even using many different methods, could not get google earth to run with with the space in the string, even when I tried to use
start "C:\Google\Google Earth\client\" googleearth.exe or start "C:\Google\Google Earth\client\googleearth.exe"

This is what I did on my system, apparently google can be cut from it's location to anywhere you want, there is nothing tied to it, you can rename the folders or take out the space with no problems. I cut it from my program (x86) folder and placed it on C:\

This is what worked for me (not using pro but it shouldn't matter).

start C:\Google\GoogleEarth\client\googleearth.exe
echo wscript.sleep 20000 > temp.vbs
start /wait temp.vbs
start C:\Windows\System32\eventvwr.exe

This is a simple workaround that will work fine.
Shorten (take out the spaces) of google as I did and since event manger won't like being relocated or renamed, simply create a shortcut for it on your C:\ and name it "a" (extension of a shortcut is .lnk). So if you follow this example it will look like this:

Code:
start C:\Google\GoogleEarth\client\googleearth.exe
ping -n 20 127.0.0.1
C:\a.lnk
You could also use the shortcut method on your googleearth.exe rather than as mentioned above if you wanted, making it even shorter.

Code:
start C:\googleearth.lnk
ping -n 20 127.0.0.1
C:\a.lnk
I also just tested what someone else wrote for a time delay and it worked. Using the VB method it would be.
Code:
start C:\Google\GoogleEarth\client\googleearth.exe
echo wscript.sleep 20000 > temp.vbs
start /wait temp.vbs
C:\a.lnk
Either of the ways work, but I prefer the simpler method. It's less code and the dos box closes on it's own and no temp.vbs to clean up.
Enjoy!

PS. There is a way to have the dos box run minimized, but I don't know how.

Strange, but when I posted this info I copied it from my notepad after testing. It looks like someone removed the "start" before each of the C:\a.lnk

Make sure that line reads
start C:\a.lnk

It will still work, but the dos box will not close.

I see the age of it, but being that I found this topic on a similiar search, decided to take the time to post my findings should someone else need assistance.
So in other words, just to help someone, unlike your comment just to annoy.
Reply With Quote
  #13  
Old 18-12-2009
David H. Lipman
 
Posts: n/a
The way to access this group is DIRECTLY with any news client via the following news
URL...

news://msnews.microsoft.com/microsof...lp_and_support

Nobody is modifying your (or anyone's) post. I'd suggest you stop
listening to Glenn Beck.
Reply With Quote
  #14  
Old 18-12-2009
Danbo342
 
Posts: n/a
Re: batch file to open 2 progs with time delay

Who keeps modifying my posts? I take the time to post helpful information, 1st someone modifies my last line in the code, taking out "Start" from the "C:\a.lnk" line, and now after some idiot posts a comment to my good deed, that message is removed and my reply is now added to my original post making it look like I am talking to Andrew... Is this the proper use of moderating?
I believe it's actually quite illegal to change what people say, is it not? So much for trying to help a future someone. I'm going to have these screenshots investigated, this is bs.
Reply With Quote
  #15  
Old 18-12-2009
John John - MVP
 
Posts: n/a
Re: batch file to open 2 progs with time delay

I hear he and Sarah Palin are an item. Hey, if they can spread lies and
innuendo so can we! If we are lucky they will move to the polar ice cap
and never be heard from again...
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows XP > Windows XP Support


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "batch file to open 2 progs with time delay"
Thread Thread Starter Forum Replies Last Post
Learning Batch file to open a program or a file Ikshana Windows Software 3 04-04-2011 08:24 PM
How to run batch file at specific time Campbel Software Development 4 27-03-2010 08:32 PM
How to run batch file each time computer boots Gannon Software Development 4 27-03-2010 06:53 PM
Is it possible to right click on cmd batch file and try to open it in a directory Kamran Operating Systems 2 26-05-2009 11:41 AM
Date and Time format in a BATCH File RogerFielden Software Development 3 20-04-2009 12:47 PM


All times are GMT +5.5. The time now is 12:10 AM.