1

I want to open IE from a batch file and wait untill it is closed before going to the next line of the batch file. How to do this? BTW iexplore command seems to be not working in Windows 7 command line. Any idea why?

Thanks...

Manoj
  • 5,011
  • 12
  • 52
  • 76

4 Answers4

4

The other methods here work if Internet Explorer isn't running.

If IE is already running though, it won't work properly. This is of course awful if a web page in IE is the starting vector for your script!

The fix I found is to use -noframemerging as a switch to iexplore.exe:

start "" /wait "%ProgramFiles%\Internet Explorer\iexplore.exe" -noframemerging "https://www.google.com"
syneticon-dj
  • 417
  • 5
  • 21
  • indeed, start /wait would return immediately if an IE window is opened already unless -noframemerging is passed as a parameter which is telling IE to start up in a new process instead of opening a new tab in the already-present process. – syneticon-dj May 07 '15 at 10:45
  • Did try that since it sounded a good approach. But my start /wait does not wait as expected. (And I check with -private that the options are well taken into account by IE...) – Zzirconium Oct 12 '15 at 15:21
1
start /wait whatever.exe

The /wait flag will make start wait until the program closes before it returns.

As for iexplore not working, you're right. That's curious... However, you can still invoke it with a full path:

start "" /wait "c:\Program Files\Internet Explorer\iexplore.exe" http://stackoverflow.com

I've updated the second command line to work around some manner of bug in start's command processing. It's weird. However, the proper way to do this is:

start /wait http://address.com
Mike Caron
  • 14,351
  • 4
  • 49
  • 77
  • /wait works for programs like notepad but fails for IE. Also if I include only the path to IE, then it opens a new command line instead of the browser. If I only give the link, it opens a new browser but still does not wait. If I try the command u have given exactly, still it does not wait untill I close the browser. – Manoj Jul 28 '10 at 04:34
  • 1
    start is stupid! When using quoted paths, you have to include a empty set of quotes first (for the title) Ex: start "" /wait "c:\random app.exe" (And you should also replace c:\Program Files with %programfiles%) – Anders Jul 28 '10 at 05:24
  • @Manoj It depends. I tested it, it works fine for IE. Just, as others have mentioned, the lifetime of the browser is funky, since you might just launch a tab in another process. – Mike Caron Jul 28 '10 at 06:18
  • @Anders Why is start stupid? And, why would you include empty quotes? That's kind of stupid, IMO. I tested my solution, and it works just fine. Note that /wait is a parameter to start, not to iexplore. Also, your answer seems to use start as well... – Mike Caron Jul 28 '10 at 06:19
  • For me also it works only when an empty quotes is placed before. I use IE 8 and Windows 7. – Manoj Jul 28 '10 at 06:28
  • Huh. That's really bizzare. NOW, it's also not working without the quotes. I swear it worked fine earlier! – Mike Caron Jul 28 '10 at 06:51
  • @Mike Caron: When the path/program string is in double quotes, you must provide the empty double quotes first, that's why I called start stupid (It was not like that on Win9x IIRC) – Anders Jul 28 '10 at 21:18
1

Browsers are complicated when it comes to process lifetime, even back in the days before tabs, IE could have more than one window open in a single process. They also often use DDE to open urls making it hard to track the "correct" process. If you want to force the user to use IE (Why not use the default browser?) you could use windows scripting host to automate IE (Automation has some problems when it comes to protected IE IIRC)

I would recommend just a simple pause:

start /wait http://example.com
echo. When you are done reading xyz, press [Enter] to continue...
pause >nul
Anders
  • 97,548
  • 12
  • 110
  • 164
  • Note that this will cause the message to be delayed until the browser quits. This could potentially be forever, if the user opens other tabs, etc. – Mike Caron Jul 28 '10 at 06:20
  • Yes, that is true, if that is a problem, just remove /wait – Anders Jul 28 '10 at 10:01
-2
call "C:\Program Files\Internet Explorer\iexplore.exe" www.google.com
call "C:\Program Files\Internet Explorer\iexplore.exe" www.stackoverflow.com
call "C:\Program Files\Internet Explorer\iexplore.exe" www.codeproject.com
echo done
pause

I tried it on windows 7 and it works perfectly....

test the code before posting ur comments.......

user409640
  • 21
  • 4