user1264377
user1264377

Reputation: 27

Close all browser windows?

I'm working on a C# app (automated bot) to open many Internet Explorer windows and visit different sites at same time.

It uses to open almost a window every 10 seconds, so, after a few minutes, I just have hundreds of windows, which, of course, slowly down my pc quite a lot...

So, I'm curious to know if there is some way to close all the active windows directly from my application, so that I can run that code in a thread or something like that, every some minutes.

Thanks in advance.

Upvotes: 0

Views: 4022

Answers (3)

Raymond Chen
Raymond Chen

Reputation: 45173

Use the InternetExplorer object to open each window and invoke the Quit method when done. This has the added benefit of closing only the windows you opened (so that windows opened by the user or other applications are unaffected).

Upvotes: 2

RB.
RB.

Reputation: 37192

I would suggest performing the automation using a library like WatiN, which will allow you to automate any mainstream browser (including IE).

Using Watin you would open and close the window like so (very simple example):

screen = new Screen("http://www.google.com")
screen.ie.ForceClose();

Upvotes: 1

StoriKnow
StoriKnow

Reputation: 5866

As @cdhowie mentioned, you can cycle through the list of running processes, do a check for iexplore and terminate that process all within a timer. If you want to delve a little deeper into which websites are being terminated (perhaps you want to create a log for use later) you can retrieve website information during the process of termination.

Upvotes: -1

Related Questions