VB cannot access controls of an existing IE browser

I need to have a VB application to press a button in an existing webpage open in a Internet Explorer 10 browser. I cannot (not allowed) to run the company app from within a VB WebBrowser control. Unfortunately my code does not seem to be working and I'm getting a VB error of "Access Denied". My goal is to press a button within the existing IE browser.

        Dim SWs As New SHDocVw.ShellWindows
        Dim oSiteManager As BaseSite
        Dim oIE As SHDocVw.InternetExplorer
        Dim oPage As String
        Dim bFoundWindow As Boolean = False

' ***** This part works - oIE does indeed get the correct Internet Explorer window (verified by get oIE InnerHtml
        For Each oIE In SWs
            If oIE.Name = "Windows Internet Explorer" Then
                ' ignore empty name
                If oIE.LocationName <> "" Then
                    ' ignore about tabs
                    If oIE.LocationURL <> "about:Tabs" Then
                        ' ignore about blank
                        If oIE.LocationURL <> "about:blank" Then
                            ' save the data somewhere...
                            ' txtStatus.Text = txtStatus.Text + oIE.LocationName & ", URL=" & oIE.LocationURL + vbCrLf

                            ' oPage = oIE.Document.body.InnerHTML
                            If oIE.LocationURL.IndexOf("/status/") > -1 Then
                                oPage = oIE.Document.body.InnerHTML
                                txtStatus.Text = txtStatus.Text + oPage + vbCrLf
                                Exit For
                            End If
                        End If
                    End If
                End If
            End If

        If Not IsNothing(oIE.Document.body) Then

' ******* The next statement is needed because the oIE is not
' This next statement does NOT throw an error, but while stepping thru it has values of "Access Denied". I cannot use the oIE control directly to access the GetElementsByTagName function (tried it) bec I got a "Cannot implicitly convert type 'System.__ComObject' to 'System.Windows.Forms.HtmlElement'") error

            Dim f1 As mshtml.IHTMLWindow2 = CType(oIE.Document.frames.item(0), mshtml.IHTMLWindow2)
            Dim theElementCollection As HtmlElementCollection = f1.document.GetElementsByTagName("input")

            For Each curElement As HtmlElement In theElementCollection
                Dim controlValue As String = curElement.GetAttribute("Value").ToString
                If controlValue = "Resume" Then
                End If

        End If
Who is Participating?
btdownloads7Connect With a Mentor Commented:
All IE10 windows are sandboxed for security purposes, so that's why you're getting the access denied error. You won't be able to run a VB script that controls anything inside an IE window -- that's the same behavior as a virus would use, and it will always get blocked
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.