Use VB application to Interact with Internet Explorer session that is already active.

I'm looking to create a VB 6 application, or if needed, another VB .NET application to interact with Internet Explorer browser sessions that are already running and not started by the VB application.  In particular, I'd like to have a VB application the is already running on the users machine that watches all IE sessions for certain prompts that are coming from a page in that session with a particular url.  If that page has a certain prompt,  then the VB application will click the prompt box for the user and also run an application already on the users machine.  Can this be done?  If so, any ideas on how to go about this?

Any an all help/suggestions are greatly appreciated and will be provided points even if they are not the solution.  Thank you.
LVL 3
ironcladsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Meir RivkinFull stack Software EngineerCommented:
>>If that page has a certain prompt
what do u mean by 'certain prompt'?
0
Bob LearnedCommented:
I believe what you are looking for is Internet Explorer automation, which allows you to "controls an instance of Windows Internet Explorer through automation."

InternetExplorer Object
http://msdn.microsoft.com/en-us/library/aa752084(VS.85).aspx
0
ironcladsAuthor Commented:
That's good information regarding IE automation.  I'll bookmark it.  Thanks.  The biggest question in my question is how do I interact with an IE session already started, but not was not started from the VB application.  In this case, the user will be starting the IE application.  I need my application to monitor opened IE browser windows and when they navigate to our Intranet site, it needs to know that and be able to interact with the browser at that point using the automation options on the MSDN link you provided.  I can probably figure out the rest, once I get my vb application to have a handle to the IE session it didn't open.  Can VB scan open applications and get a hook into an already open IE session?

Any thoughts?  Thank you again.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Bob LearnedCommented:
Here is a class that I use that to interface with open IE sessions.

You need to add these references for the code to work:

COM reference to 'Microsoft Internet Controls'
.NET reference to Microsoft.mshtml
' Add a COM reference to 'Microsoft Internet Controls' to the project.
' Add a .NET reference to Microsoft.mshtml to the project.

' NOTE:
' Don't add an Imports mshtml if you want your Intellisense to work.

Imports System
Imports System.Collections.Generic
Imports SHDocVw

Public Class InternetExplorerWindows

  Public Shared Function GetWindows() As Dictionary(Of String, String)
    Dim list As New Dictionary(Of String, String)
    For Each window As InternetExplorer In New ShellWindows()

      ' Skip Windows Explorer instances, since the Document type is IShellFolderViewDual2.
      If TypeOf window.Document Is mshtml.HTMLDocument Then
        list.Add(window.LocationURL, CType(window.Document, mshtml.HTMLDocument).body.innerHTML)
      End If
    Next window
    Return list
  End Function

  Public Shared Function GetIFrameHTML(ByVal frameID As String) As Dictionary(Of String, String)
    Dim list As New Dictionary(Of String, String)
    For Each window As InternetExplorer In New ShellWindows()

      ' Skip Windows Explorer instances, since the Document type is IShellFolderViewDual2.
      If TypeOf window.Document Is mshtml.HTMLDocument Then
        Dim doc As mshtml.HTMLDocument = CType(window.Document, mshtml.HTMLDocument)
        If doc.getElementById(frameID) IsNot Nothing Then
          Dim frame As mshtml.HTMLIFrame = CType(doc.getElementById(frameID), mshtml.HTMLIFrame)
          Dim window2 As mshtml.HTMLWindow2 = CType(frame.contentWindow, mshtml.HTMLWindow2)
          Dim windowDocument As mshtml.IHTMLDocument2 = CType(window2.document, mshtml.IHTMLDocument2)
          list.Add(window.LocationName, windowDocument.body.outerHTML)
        End If
      End If
    Next window
    Return list
  End Function

End Class

Open in new window

0
ironcladsAuthor Commented:
I've created a VB.Net project and got it to build with the code you provided.  Call me dense, but what do I call in the form1_Load?  Do I put GetIFrameHTML() or GetWindows() or am I even doing it right?

Thanks.
0
Bob LearnedCommented:
The GetIFrameHTML was added to be able to get the HTML for an IFrame, and you can ignore that method for most calls.  GetWindows loops through each open window, and makes sure that the window is for Internet Explorer, and not Windows Explorer (IShellFolderViewDual2).
0
ironcladsAuthor Commented:
I'm getting these errors when I try to build it now - (See errors.gif)

I'm attaching a txt document with the code from the project.  Also if you want to see my project, please download it from this url:

http://www.ironclads.com/temp/WindowsApplication2.zip

Thank you again for your help thus far.  Much appreciated.
code.txt
errors.gif
0
Bob LearnedCommented:
Right-click on the project, in the Solution Explorer, and select "Add", and the "Class" sub-menu.  Type InternetExplorerWindows in the file name.  Copy and paste the code into that new file.

This isn't VB6, so a "Call" is not necessary.

"Public Shared" methods are static members, and don't require an instance to call the method, but you need the class name:

Here is some sample code that you can borrow from:


   ' Get all the open Internet Explorer instances (URL and HTML) in a dictionary.
   Dim windowList As Dictionary(Of String, String) = InternetExplorerWindows.GetWindows()

   ' Loop through the dictionary, and pull out the URL from the key, and the HTML from the value.
   For Each url As String In windowList
       Dim html As String = windowList(url)
   Next

Open in new window

0
ironcladsAuthor Commented:
Sorry for bugging you further.  I still can't get it to build.  I'm including 3 images of what is occurring.  I'm sure you noticed, I've worked mostly in VB6 so this .NET stuff is fairly new to me.

Thank you again.
InternetExplorerWindows.gif
form1.gif
errors.gif
0
Bob LearnedCommented:
If you added the references that I mentioned earlier (COM - Internet Controls and .NET - mshtml), then you are missing an Imports SHDocVw from the top of the class module.

The code example has 2 comments about the project references, and the Imports statements, that I don't see in your code.

Imports System
Imports System.Collections.Generic
Imports SHDocVw
0
ironcladsAuthor Commented:
Ok, I see.  Those references needed to be a part of the class.

I'm getting only 1 error now.  I'm not certain why it doesn't think it's a string.  Any suggestion(s) for me?

Thank you.
errors.gif
0
Bob LearnedCommented:
Oops, my bad (coding in the comment block) (d'oh).  You need to access the Keys collection in the For Each loop.


  ' Get all the open Internet Explorer instances (URL and HTML) in a dictionary. 
   Dim windowList As Dictionary(Of String, String) = InternetExplorerWindows.GetWindows() 
 
   ' Loop through the dictionary, and pull out the URL from the key, and the HTML from the value. 
   For Each url As String In windowList.Keys
       Dim html As String = windowList(url) 
   Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ironcladsAuthor Commented:
Most excellent.  I can now see the IE sessions and now I can work with them from here.  Your help is greatly appreciated and was most needed.  Danke, Thank you, Muchos Gracias, etc. etc.  Enjoy!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.