Forum Discussion

ANW's avatar
ANW
Contributor
13 years ago

Sure way of stopping IE9 process every time??

Ok, so I am getting frustrated with IE process. I have some functions that try to close the process nicely, and 90% of the time that works, but sometimes it just refuses to close. So I included a terminate method if it wouldn't close properly. That doesn't seem to work much better.



So I am looking for some advice on how to be sure that the process closes every time I want it to.



The code I have look something like this:








procedure StartBrowser(browser, startURL: string); 

var

  Commandline : string;

begin

  // If browser already exists, we close it down

  browserProcess := Sys.WaitProcess(browser,100); 

  if browserProcess.exists then

    StopBrowser;

    

  // Setting up start page

  Commandline := startURL;

...... snip .....

end;








procedure StopBrowser;

var

counter : integer;

begin

  browserProcess.close;

  counter := 0;

  repeat

    delay(200);

    inc(counter);  

  until

    (browserProcess.exists = false) OR (counter = 50);

    

  if browserProcess.exists then begin

    Log.error('Browser process could not be closed',

              'Browser process did not close within timeout period. ');

    browserProcess.terminate;

  end

  else

    Log.message('Browser process closed',

                'Browser process <' + VarToStr(browserProcess.Name) + '> was closed successfully');

                

  Delay(1500);

end;


So basically what I do is that if the process is already running when I want to start the browser, I try to close it first. I send the close method to the process, and wait up to 10 seconds or until the process no longer exists. If it still exists after 10 seconds I send a terminate method.



Sadly, even with the terminate method, the Start script then complains that there is already a process running.



How can I make a function that will ensure that the IE browser process shuts down correctly every time??



I have not had these problems with FF3.6/FF4 browser at all.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    IE actually creates multiple processes when it runs.  Depending upon which of the processes you shut down as to whether or not it will shut down all processes.  



    What you're going to need to do is detect how many browser processes for IE are actually running and then loop through and close them all, checking after each close call to see if you managed to close them all.



    My preferred method, though, is to fiddle with the windows registry to tell IE to not spawn multiple processes.  I don't have the link readily at my fingertips but it was shared on this forum somewhere how to do so.
  • ANW's avatar
    ANW
    Contributor
    Yeah, I tried that, and it seems to be working so far. So I hope that it will consistently shut down when I want it to.
  • I found this:

    http://blog.smartbear.com/software-quality/web-testing-disabling-multiple-processes-of-internet-explorer-8/





    1. Open the registry editor.


    2. Go to the HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMain section and locate the TabProcGrowth key. If the key does not exist, create a new DWORD (32-bit) Value or String Value and name it as TabProcGrowth accordingly.


    3. Set the value of the TabProcGrowth key to 0. This will instruct IE to open all of the tabs within the same iexplore.exe process.