views:

413

answers:

4

Hello all,

I have created a small command that will let me launch Internet Explorer. However, I wish to close the small command prompt that shows up when I launch IE. How can I do this? This is my current code:

"%ProgramFiles%\Internet
Explorer\iexplore.exe"
http://localhost/test.html
PAUSE

I am guessing if I take out the Pause. It will close the CMD box upon closing IE??

Also is there another command that I can use to simply create a command that will let me add something to the Menu with a small icon, which in turn runs the above. Is this complicated? Any tutorials I can use?

Thanks all

+2  A: 

you need this on the end

&& exit

For example

"%ProgramFiles%\Internet Explorer\iexplore.exe" http://google.co.uk && exit
Russ Cam
Strange I have placed EXIT at the end but it only closes after I close IE. I was hoping to close it when it spawns off the IE process, possible?
Abs
Just tried that same thing happens. I am on Vista by the way if that helps! I thought this was going to be a piece of cake but I haven't had my cake yet! I appreciate any more help.
Abs
If I put an exit at the top, it obviously closes the CMD!
Abs
No problem. I managed to get it working with the start title thing as suggested. +1 for continued help. Out of interest what OS are you running for the above to work. I am worried my current solution may not work on most Windows versions!
Abs
Windows XP. But this should work in the CMD shell in Vista and 7 and right back to 3.1, I believe.
Russ Cam
I also couldn't get this working. On my XP machine the command window stays open until I close the browser. Maybe there is some misunderstanding in how the OP wants to call the script?
0xA3
I see. Thanks, I will try it on a different machine as I thought that would work.
Abs
Aha - I don't think it's working because you've got it in a CMD/BAT file but I thought you were entering it into the CMD shell. Apologies, my mistake. This is not a bad resource to begin with - http://technet.microsoft.com/en-us/library/cc723564.aspx
Russ Cam
Ah, I see now. This is for calling interactively.
0xA3
A: 

You have to add 'start' in front of every program you launch, elsewhere your script is going to wait until it's finished.

svens
This just spawned another CMD prompt!
Abs
well just put it in front of your IE, that is what I wanted to say with programm
svens
+4  A: 

Use the start command:

start "title" "%ProgramFiles%\Internet Explorer\iexplore.exe" http://www.example.com
0xA3
I am impressed! I did not know that, Thank you!
Abs
Interestingly, this appears to launch the default browser, as it launches FireFox for me :)
Russ Cam
why "title"?? use start "" "foo.exe"
Anders
It is for no reason, just to make the sample more explicit. I thought people might wonder more about an empty string as the first parameter. But it seems I've been wrong ;-)
0xA3
@Russ: Did you omit the first parameter that is specifying the title? If you do start.exe will use the executable path as the title and then start the URL which gets opened by the default browser.
0xA3
A: 
@echo off
start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "http://www.example.com"
exit /b

But you really should not force IE, but use the default browser:

@echo off
start http://www.example.com
exit /b

exit /b does not work on win9x IIRC, so if you need to support every version of windows and close the terminal window if the user double clicks your batch file, go with:

@echo off
start http://www.example.com
cls
Anders
"But you really should not force IE, but use the default browser": Maybe the requirement is to **force** the use of IE for a certain URL? I guess the OP will know better ;-)
0xA3