4

I have some scheduled tasks that opens IE Windows on the background to execute periodic routines.

The problem is, as the day goes on, several IE instances are left executing on the background and this leaves less free memory to work on the server.

The tasks are configured to stop and kill still running instances when it starts and it's also configured to kill instances running for more than 1 hour. All this seems to not work.

I've tried to include a JavaScript window.close() at the bottom of the page, but it didn't work. I suspect it's becouse of security settings that asks the user when there are non interactive scripts trying to close the window.

Q: Is there a way to close those windows after they have done it's work automatically?

Edit:

These are scheduled tasks in Windows Task Scheduler that executes Internet Explorer directly passing na URL to open.

1
  • It seems that there is no way of doing this only with the scheduled tasks or Windows native comands and utilities. I can't close all instances of the browser sice I have more routines that run at different time intervals. I've used a script to work this out. Jun 22, 2015 at 16:39

4 Answers 4

1

The following VBScript will enumerate all windows, find the ones that match the URL you would like to find and then close the tab/window.

Set sa = CreateObject("Shell.Application")
Set windows = sa.Windows()

For Each window In sa.windows
    If left(window.LocationUrl, 5) <> "file:" Then
            ' logic for selecting windows goes here
            If InStr(window.locationUrl,"www.google.com") Then window.Quit()
            If UCase(window.locationUrl) = UCase("about:tabs") Then window.Quit()
    End If
Next

The If InStr section can be used to do partial URL search, while the If UCase can be used for exact string comparison. Adjust accordingly. Shouldn't be too difficult to modify script pass it a text file with a list of URLs to search for and close the windows found.

You can test it by opening multiple tabs in IE, opening www.google.com and leaving others in about:Tabs, execute the script, and watch as the tabs/windows close.

This script is based on one found here.

1

Not a full answer, but something you can hopefully work with...

Schedule a new Task and use it to fire off Windows' TaskKill, and forcefully kill all processes with the Image Name "iexplorer.exe" that have been running for more than an hour:

Something like taskkill /F /IM iexplore.exe /FI "CPUTIME gt 1:00:00".

3
  • +1 This is realy helpfull. I will give some more time to see if someone else have another idea, but I think I'm going with this one. Apr 9, 2014 at 14:41
  • Just to give feedback about this: I've tried this and it seems not to work. The instances of IE remain in task manager with 00:00:00 CPU time. Jun 22, 2015 at 16:32
  • And one thing I had to do was input the time with a leading zero: 01:00:00. Jun 22, 2015 at 16:33
1

My solution is to open the browser, and close it immediatly after execution, but called scripts should be modified so there execution are not endend by closing the browser.

To do so, in PHP, you can add this at top of your script so browser status has no effect on PHP execution state :

// So execution is triggered but can be aborted by closing the browser
ignore_user_abort(true); 
// Even if closing browser has no more effect, time limit should be set to 
set_time_limit(300); 

Then, in a scheduled windows batch, you can do

REM Call it
START http://.../mycode.php
REM Wait a little
ping 127.0.0.1 -n 6 > nul
REM Kill Them All
TASKKILL /F /IM iexplore.exe
0

What kind of scheduled task? Are you invoking iexplore.exe directly, or are you spawning it in VBScript or something?

If you're spawning it in VBScript, you need to explicitly free the COM server ActiveX object in your vbscript code before your script exits, by Setting it to Nothing.

If not...

This is a kluge (a clever workaround that doesn't solve the root of the problem but gets it done anyway), but...

  • Write a program in your favorite programming language that spawns whatever process does your IE thing, keeps track of the process ID in memory, and kills it whenever some "exit condition" is met. You then just have to somehow signal to the environment (writing to a file, sending an IPC message, or something like that) from within IE that your processing is done, so the outer process knows to kill IE. Then, in the outer process, use the TerminateProcess() system call to forcibly close IE. It'll close for sure then, unless it's waiting on a hung kernel thread, which would probably be due to a device driver malfunction.
1
  • These are scheduled tasks in Windows Task Scheduler that executes Internet Explorer directly passing na URL to open. This came to my mind, but I'm willing to find a way to make it without creating a dependency on other applications, if there's one. Feb 28, 2014 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .