WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: phoneman on January 31, 2014, 12:53:40 PM

Title: To many IE processes
Post by: phoneman on January 31, 2014, 12:53:40 PM
I have a problem with my UDF.  This scans a page that I have open and refreshes it every 10 seconds.  I can do that all day long and it works wonderful.  Now, I'm trying to do a little more.  I want it to count the links in the page.  If there are more than 5 after the screen refresh, I want my computer to beep to get my attention. 

The trouble is, it eventually fails or runs my computer resources into the mud.  Opening task manager, I can see that I have a whole bunch of IE windows open.  I'm thinking that I'm not closing everything in the UDF before the app continues.  I just don't see what I'm not closing.  I only open 1 object so I'm only closing 1 object.

Any help would be appreciated. 

#DefineFunction  countlinks(refresh_url)
Browser = ObjectOPEN("InternetExplorer.Application")
browser.navigate(refresh_url)
while browser.readystate <> 4
timedelay(0.5)
endwhile
BrowserDoc = Browser.Document
Links = BrowserDoc.Links
numberofLinks = Links.Length
if  numberofLinks > 5 then beep
ObjectClose(Browser)
#EndFunction



arefname = ""
refresh_url = "http://MyURL.html"
n = 10
shelllist=ObjectOpen("Shell.Application")
While  1
  cnt=shelllist.Windows.count
  For xcnt=0 to cnt-1
    obrowser=shelllist.Windows.Item(xcnt)
    If obrowser == 0 Then Continue
    If obrowser != 0 Then fname = obrowser.fullname

    If StrIndexNC(fname, "iexplore.exe", 0, @FWDSCAN) > 0
      If obrowser != 0 Then current_url = obrowser.LocationURL
      If obrowser == 0 Then Continue
      If StrIndexNC(current_url,refresh_url,0,@FWDSCAN) > 0 Then obrowser.Refresh ;does simple IE refresh
      If StrIndexNC(current_url,refresh_url,0,@FWDSCAN) > 0 Then countlinks(refresh_url) ;after refresh, count links, beep if there are more than 5.
    EndIf
  Next
  obrowser = 0
  TimeDelay(n)
EndWhile

obrowser = 0
ObjectClose(shelllist)
Title: Re: To many IE processes
Post by: Deana on January 31, 2014, 12:58:43 PM
Closing an object doesn't necessarily stop the process. InternetExplorer.Application has a Quit method to close the explorer. http://msdn.microsoft.com/en-us/library/ms970456.aspx

However you probably don't want to instantiate  the InternetExplorer.Application everytime you call your countlinks udf. rather pass the browser object into your UDf function

Just out of curiosity, What version of WinBatch are you running?
Title: Re: To many IE processes
Post by: phoneman on January 31, 2014, 01:03:14 PM
Running 2013c.  I haven't updated to 2014a yet.
Title: Re: To many IE processes
Post by: phoneman on January 31, 2014, 01:07:06 PM
So just add browser.quit above Object close?
Title: Re: To many IE processes
Post by: Deana on January 31, 2014, 01:14:16 PM
No actually. I would recommend revising your code so that you don't instantiate the browser object but rather reuse the object. Here is some revised code that should help:

Code (winbatch) Select
arefname = ""
refresh_url = "http://www.winbatch.com"
n = 10
shelllist=ObjectOpen("Shell.Application")
While  1
  cnt=shelllist.Windows.count
  For xcnt=0 to cnt-1
    obrowser=shelllist.Windows.Item(xcnt)
    If obrowser == 0 Then Continue
    If obrowser != 0 Then fname = obrowser.fullname

   If StrIndexNC(fname, "iexplore.exe", 0, @FWDSCAN) > 0
      If obrowser != 0
         current_url = obrowser.LocationURL
         If StrIndexNC(current_url,refresh_url,1,@FWDSCAN) > 0
            obrowser.Refresh ;does simple IE refresh
            ;after refresh, count links, beep if there are more than 5.
            BrowserDoc = obrowser.Document
            Links = BrowserDoc.Links
            numberofLinks = Links.Length
            If numberofLinks > 5 then beep
         Endif
      Else
         Continue
      Endif   
   EndIf
  Next
  obrowser = 0
  TimeDelay(n)
EndWhile

obrowser = 0
ObjectClose(shelllist)
exit
Title: Re: To many IE processes
Post by: phoneman on January 31, 2014, 02:07:32 PM
That's working nice.  I put this together so many ways, I missed the obvious.
Title: Re: To many IE processes
Post by: phoneman on January 31, 2014, 03:22:02 PM
Here is something interesting.

I said it worked but it only works when I am pausing the script. 

Snippit of the code above with pause added.

Links = BrowserDoc.Links
pause("Links",Links)  ; <- If I rem this line, then the numberoflinks is always 0.
numberofLinks = Links.Length
pause("numberofLinks",numberofLinks)

Like I said, I am at 2013c, I could update to 2014a to see if it makes a difference.
Title: Re: To many IE processes
Post by: phoneman on January 31, 2014, 03:56:28 PM
Upgraded to 2014a and ran the script from 2 different computers.  Still the same results.  If I add the first pause, I can get 55 links on http://www.winbatch.com.  If I rem it out, it says 0 links.
Title: Re: To many IE processes
Post by: Deana on January 31, 2014, 11:24:40 PM
Maybe try adding a short TimedDelay after the refresh.
Title: Re: To many IE processes
Post by: phoneman on February 03, 2014, 12:57:22 PM
That worked, thanks.