Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there a way to close IE browser programmatically?

2,917 views
Skip to first unread message

blabla12345

unread,
Jul 13, 2010, 8:50:07 PM7/13/10
to
Another thread alluded to it but I didn't find the solution
satisfactory.
What I'd like to do is for a software installation package to start IE
and run the final configuration and close the browser.

Just searched for "launch IE quietly/silently" for a possible to no
avail, so, the question stand.

Many thanks as usual.

foxidrive

unread,
Jul 13, 2010, 10:58:01 PM7/13/10
to

What if IE is running on the PC before your installation start? The
user wouldn't appreciate it being closed.

You can do this in batch

1) detect if MSIE is open and store the info
2) do your install
3) if MSIE was started by your install then close MSIE

The tool to find out if MSIE was running is tasklist.exe but it is not
available on all OS. Ditto with taskkill.exe which you would use to
close MSIE.


--
Regards,
Mic

blabla12345

unread,
Jul 13, 2010, 11:33:34 PM7/13/10
to
On Jul 13, 10:58 pm, foxidrive <got...@woohoo.invalid> wrote:
> On Tue, 13 Jul 2010 17:50:07 -0700 (PDT), blabla12345
>

Great, thank you very much, Mic.

Don

blabla12345

unread,
Jul 14, 2010, 9:25:15 AM7/14/10
to

But Mic, there's an issue. When the batch script has something like
the following the taskkill.exe utility did not kill the loaded IE:
1) launch IE, do some stuff;
2) Wait for 40 second for IE to do its job (ping -n 40 >nul)
3) close IE (taskkill -im iexplore.exe)

My testing with my Vista Pro box last night did not seem to complete
the above 2) and 3). And it seems rightly so because batch is
procedural. So, is there a way to solve this problem with batch?

Thanks.

Don

foxidrive

unread,
Jul 14, 2010, 10:33:55 AM7/14/10
to
On Wed, 14 Jul 2010 06:25:15 -0700 (PDT), blabla12345
<tatat...@gmail.com> wrote:

>> > What if IE is running on the PC before your installation start?  The
>> > user wouldn't appreciate it being closed.
>>
>> > You can do this in batch
>>
>> > 1) detect if MSIE is open and store the info
>> > 2) do your install
>> > 3) if MSIE was started by your install then close MSIE
>>
>> > The tool to find out if MSIE was running is tasklist.exe but it is not
>> > available on all OS.  Ditto with taskkill.exe which you would use to
>> > close MSIE.
>>

>But Mic, there's an issue. When the batch script has something like
>the following the taskkill.exe utility did not kill the loaded IE:
>1) launch IE, do some stuff;
>2) Wait for 40 second for IE to do its job (ping -n 40 >nul)
>3) close IE (taskkill -im iexplore.exe)
>
>My testing with my Vista Pro box last night did not seem to complete
>the above 2) and 3). And it seems rightly so because batch is
>procedural. So, is there a way to solve this problem with batch?

Try it from the command line. Here is what happens in XP Pro and note
the /f in the second invocation.

===[paste]===
M:\>taskkill /im iexplore.exe
SUCCESS: The process "iexplore.exe" with PID 4192 has been terminated.
SUCCESS: The process "iexplore.exe" with PID 6316 has been terminated.

M:\>taskkill /f /im iexplore.exe
SUCCESS: The process "iexplore.exe" with PID 3068 has been terminated.
SUCCESS: The process "iexplore.exe" with PID 7768 has been terminated.
===[paste]===


--
Regards,
Mic

blabla12345

unread,
Jul 14, 2010, 2:36:34 PM7/14/10
to

Mic,

I'm on Vista Pro, the 2 command sets made no difference. Both closed
IE respectively. I understand the /f switch is a forced kill. I was
concerned that batch stops after IE launch.

Thanks.

Don

foxidrive

unread,
Jul 14, 2010, 10:42:52 PM7/14/10
to
On Wed, 14 Jul 2010 11:36:34 -0700 (PDT), blabla12345
<tatat...@gmail.com> wrote:

>> >But Mic, there's an issue.  When the batch script has something like
>> >the following the taskkill.exe utility did not kill the loaded IE:
>> >1) launch IE, do some stuff;
>> >2) Wait for 40 second for IE to do its job (ping -n 40 >nul)
>> >3) close IE (taskkill -im iexplore.exe)
>>
>> >My testing with my Vista Pro box last night did not seem to complete
>> >the above 2) and 3).  And it seems rightly so because batch is
>> >procedural. So, is there a way to solve this problem with batch?
>>
>> Try it from the command line.  Here is what happens in XP Pro and note
>> the /f in the second invocation.
>>
>> ===[paste]===

>> M:\>taskkill /f /im iexplore.exe
>> ===[paste]===


>
>I'm on Vista Pro, the 2 command sets made no difference. Both closed
>IE respectively. I understand the /f switch is a forced kill. I was
>concerned that batch stops after IE launch.

So it works ok. Your batch file will work too - but your ping command
had incorrect syntax.

Try this:

@echo off
start "" "%ProgramFiles%\Internet Explorer\iexplore.exe"
ping -n 40 localhost >nul
taskkill /f /im iexplore.exe


--
Regards,
Mic

blabla12345

unread,
Jul 14, 2010, 11:05:10 PM7/14/10
to

I just looked at my batch file, it did have a target (localhost), my
bad, for the omission in previous posting.

As I recall my installation launched IE and did a bit of work (will
always be less than 1 minute I can almost guaranttee it) and then
stayed that way for about 2 minutes then I closed it. I don't
understand why. Thanks tho.


Esra Sdrawkcab

unread,
Jul 15, 2010, 7:00:50 AM7/15/10
to
On Thu, 15 Jul 2010 03:42:52 +0100, foxidrive <got...@woohoo.invalid>
wrote:

Works here (XP Pro)

--
Nuns! Nuns! Reverse

Todd Vargo

unread,
Jul 15, 2010, 7:01:03 AM7/15/10
to

======================
You didn't say what IE does. Have you tried including /T to the taskkill
command?

taskkill /f /im iexplore.exe /t


--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)


--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Todd Vargo

unread,
Jul 15, 2010, 7:26:39 AM7/15/10
to

Ditto. Note, OP did not comment on running the test batch exactly as posted.
OP commented on their installer instead using the phrase, "as I recall".

I recommend the OP post their batch code exactly as used when it fails.
Also, post any output displayed too. Taskkill should be displaying some
output.

ten.n...@virgin.net

unread,
Jul 15, 2010, 9:23:21 AM7/15/10
to

You could, (depending upon some factors), use WMIC for the opening and
closing of IE.

::----- START -----
@Echo off & Setlocal enableextensions
For /f "tokens=2*" %%a In ('Reg query^
"HKLM\SOFTWARE\Classes\Applications\iexplore.exe\shell\open\command"^|^
Find "_SZ"') Do Call :Sub %%b
Goto :Eof
:Sub
For /F "usebackq tokens=2 delims==; " %%# In (
`Wmic Process CALL Create '%~1'^|Find "ProcessId"`) Do Set "_=%%#"
Ping -n 40 127.0.0.1 1>NUL
Wmic Process WHERE "ProcessId='%_%'" CALL Terminate 1>NUL
::------ END ------

The idea of this is that it uses the process handle of the instance of IE
opened in order to closes that same instance. This means that if you
already have an instance of IE open then it should be left untouched by
this process.

foxidrive

unread,
Jul 15, 2010, 4:56:37 PM7/15/10
to

This has an issue that taskkill also has: When MSIE starts the next time
it gives me a warning message box that "the last session terminated...
restore your last session?" type thing.


On my machine the code above also fails to start MSIE because the output
from reg.exe must be different in XP.

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\iexplore.exe\shell\open\command

<NO NAME> REG_SZ "C:\Program Files\Internet Explorer\IEXPLORE.EXE" %1

--
Regards,
Mic

ten.n...@virgin.net

unread,
Jul 15, 2010, 5:20:41 PM7/15/10
to

This is my reg.exe output on Vista:
::----- CONSOLE -----
C:\Users\TenNigriv>reg query


"HKLM\SOFTWARE\Classes\Applications\iexplore.exe\shell\
open\command"

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\iexplore.exe\shell\open\command

(Default) REG_SZ "C:\Program Files\Internet
Explorer\iexplore.exe" %1
::-------------------
It doesn't output the top line but the important line appears to be the
same.
*, in this case %%b should still be set to:
"C:\Program Files\Internet Explorer\iexplore.exe" %1

I would think that the message box is a 'feature' which if bypassed would
probably, in the main, be a bad idea.

ten.n...@virgin.net

unread,
Jul 15, 2010, 5:35:05 PM7/15/10
to

Not that all of this matters very much because I've just had an opportunity
to test it and it appears that with another instance of IE already open,
the script fails to terminate the newly created window!

foxidrive

unread,
Jul 16, 2010, 12:27:04 AM7/16/10
to
On Thu, 15 Jul 2010 22:35:05 +0100, ten.n...@virgin.net wrote:

>>> <NO NAME> REG_SZ "C:\Program Files\Internet Explorer\IEXPLORE.EXE" %1

>> (Default) REG_SZ "C:\Program Files\Internet

>> It doesn't output the top line but the important line appears to be the


>> same.
>> *, in this case %%b should still be set to:
>> "C:\Program Files\Internet Explorer\iexplore.exe" %1

No, the line from mine on XP has an extra token because of the space in
the first term.



>> I would think that the message box is a 'feature' which if bypassed would
>> probably, in the main, be a bad idea.

True. It's just that these methods adds something that the user may not
expect.

>Not that all of this matters very much because I've just had an opportunity
>to test it and it appears that with another instance of IE already open,
>the script fails to terminate the newly created window!

Confirmed.


--
Regards,
Mic

Esra Sdrawkcab

unread,
Jul 16, 2010, 8:09:32 AM7/16/10
to
On Thu, 15 Jul 2010 14:23:21 +0100, <ten.n...@virgin.net> wrote:

Given these difficulties can I suggest a scripted keypress solution?
(i.e. use a known, hopefully unique name for the iexplorer window and send
Alt-F4 to it.)

Scriptit I used to use. I don't know if there are newer better ones around
now.
{scroogle search}. Apparently Autoit is the one.

--
Nuns! Nuns! Reverse

blabla12345

unread,
Jul 16, 2010, 11:11:46 AM7/16/10
to
On Jul 16, 8:09 am, "Esra Sdrawkcab" <ad...@127.0.0.1> wrote:

Guys, thank you all for the efforts.

Here's some more details.

I use a zip to exe utility called winRar
to turn the zip file to an exe installer.

And the last batch file has the following routine for launching
IE to do the last leg of a little configuration.
:launch
REM regardless launch IE for the installation


"C:\Program Files\Internet Explorer\iexplore.exe"

http://127.0.0.1:8600/KNB2/verifyAccessDB.cfm
REM give it 40 seconds to do its work


ping -n 40 localhost >nul

REM close IE
taskkill /im iexplore.exe

Comment:
I could have added the /f switch for the taskkill.exe for the last
line above but I forgot, not sure it would make the critical
difference.

Oddity (my observation):
For the last test installation (7/14/2010), the installer put
KnowledgeNoteBook directory under "Program Files" but by design and in
the past, it was directly under C:\ drive. I'm not sure if MS or
something else is messing me up, not making an accusation but
speculating.

blabla12345

unread,
Jul 16, 2010, 11:15:07 AM7/16/10
to
On Jul 16, 8:09 am, "Esra Sdrawkcab" <ad...@127.0.0.1> wrote:

Oh, in case some of you would want to see EXACTLY how the installer
would work with your box, here's the URL to try it,
http://www.knowledgenotebook.com/
(I use the root URL for additional information such as installation
instructions). Thanks.

As for the alternate key or the like, I'm a bit concerned that it's an
extra step... many users under 20 are spoiled...

foxidrive

unread,
Jul 16, 2010, 2:27:59 PM7/16/10
to
On Fri, 16 Jul 2010 08:11:46 -0700 (PDT), blabla12345
<tatat...@gmail.com> wrote:

>Oddity (my observation):
>For the last test installation (7/14/2010), the installer put
>KnowledgeNoteBook directory under "Program Files" but by design and in
>the past, it was directly under C:\ drive. I'm not sure if MS or
>something else is messing me up, not making an accusation but
>speculating.

It's my observation that newer versions of windows don't like
users/programs writing to the root or anywhere except their user
folders.


--
Regards,
Mic

blabla12345

unread,
Jul 16, 2010, 6:13:04 PM7/16/10
to
On Jul 16, 2:27 pm, foxidrive <got...@woohoo.invalid> wrote:
> On Fri, 16 Jul 2010 08:11:46 -0700 (PDT), blabla12345
>
> <tatata9...@gmail.com> wrote:
> >Oddity (my observation):
> >For the last test installation (7/14/2010), the installer put
> >KnowledgeNoteBook directory under "Program Files" but by design and in
> >the past, it was directly under C:\ drive.  I'm not sure if MS or
> >something else is messing me up, not making an accusation but
> >speculating.
>
> It's my observation that newer versions of windows don't like
> users/programs writing to the root or anywhere except their user
> folders.
>
> --
> Regards,
> Mic

Ok, thanks, Mic.

Don

0 new messages