Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Open and Close Internet Explorer from batch file?

I Have a batch file which has to launch Internet explorer and open www.google.com. When the whole page loads finishing it should kill the IE process i.e. close all instances of IE in that system. My batch file has following two lines.

iexplore.exe "www.google.com"
taskkill /IM iexplore.exe /F

But after loading it is not closing the IE instance.

If I am having seperate batch file with with only single line taskkill /IM iexplore.exe /F. This batch file closes the IE instance.

What is going wrong in First Batch file.

P.S Batch file is in Internet Explorer folder of program files.

like image 726
Veer Avatar asked Jun 17 '15 08:06

Veer


People also ask

How do I close Internet Explorer from CMD?

Run the following command at an elevated command prompt to disable Internet Explorer 11: dism /online /Remove-Capability /CapabilityName:Browser. InternetExplorer~~~~0.0. 11.0 .

What is @echo off in batch script?

When echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt again, type echo on. To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type: Copy. @echo off.

How do I start Internet Explorer from the command line?

Open Internet Explorer from Command Prompt Like any other program, the Internet Explorer browser can also be launched from Command Prompt. In the Command Prompt, type @start iexplore and then press Enter key to open Internet Explorer browser.


1 Answers

I don't understand exactly your aim to open and to close immediately Internet explorer ? but here is an example with a sleep to show you how it does work !

@echo off
Title Start and Kill Internet Explorer
Mode con cols=75 lines=5 & color 0B
echo(
echo                     Launching Internet Explorer ...
Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "www.google.com"
:: Sleep for 20 seconds
Timeout /T 20 /NoBreak>NUL
echo(
echo            Hit any Key to kill all instances of Internet Explorer
Pause>nul
Cls & Color 0C
echo(
echo              Killing Internet Explorer Please wait for a while ...
Taskkill /IM "iexplore.exe" /F
pause

And if you want to see more features like how to start a process and how to kill one process or multiple processes at once that interact with user input with a dynamic menu you should take a look at this post ==> How to check and correct user input when he omit the extension .exe to kill the process?

Try this alternative without confirmation from the user input :

@echo off
Title Start and Kill Internet Explorer
Mode con cols=75 lines=5 & color 0B
echo(
echo                     Launching Internet Explorer ...
Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "www.google.com"
:: Sleep for 10 seconds, you can change the SleepTime variable
set SleepTime=10
Timeout /T %SleepTime% /NoBreak>NUL
Cls & Color 0C
echo(
echo              Killing Internet Explorer Please wait for a while ...
Taskkill /IM "iexplore.exe" /F
like image 132
Hackoo Avatar answered Sep 23 '22 18:09

Hackoo