Advertisement

04.17.2008 at 10:39AM PDT, ID: 23331841
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.5

HTML parsing using mshtml causing exceptions on Windows XP SP2

Asked by gkamckenney in Microsoft Visual Basic.Net

Tags:

I have a program that reads through the active IE6 browser, identifies a specific frame and parsers through the page to find a value. This works great on many different development machines such as Windows 2003 Server and Windows XP. Now the client is testing in their environment and they get the following error:

System.UnauthorizedAccessException: Access is denied.

   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at mshtml.HTMLWindow2Class.get_document()
   at HotKeyFormVB.Form1.InternetExplorerWindows.GetWindows()
   at HotKeyFormVB.Form1.hotKey_Pressed(Object sender, HotKeyPressedEventArgs e)
   at HotKeyFormVB.vbAccelerator.Components.HotKey.HotKeyForm.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I have also attached the code below.

Any help is much appreciated!

JohnStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
Private Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Integer
 
    Public Class Window
        Public BodyHtml As String
        Public LocationName As String
        Public Url As String
        Public Hwnd As Integer
    End Class
 
    Public Class InternetExplorerWindows
 
        Public Shared Function GetWindows() As List(Of Window)
 
            Dim list As New List(Of Window)
            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
 
                    ' Get the HTML document represented by the browser's Document property.
                    Dim doc As mshtml.HTMLDocument = CType(window.Document, mshtml.HTMLDocument)
 
                    ' Create a class to collect important information to return to the caller
                    Dim win As New Window()
 
                    If doc.getElementById("TargetContent") IsNot Nothing Then
                        ' Get the HTML from the IFrame element, if it exists.
                        Dim frame As mshtml.HTMLIFrame = CType(doc.getElementById("TargetContent"), mshtml.HTMLIFrame)
                        Dim windowDocument As mshtml.HTMLDocument = CType(frame.contentWindow, mshtml.HTMLWindow2).document
 
                        win.BodyHtml = windowDocument.body.outerHTML
                    Else
                        ' Get the HTML from the main document.
                        win.BodyHtml = doc.body.outerHTML
                    End If
 
                    ' Store info needed from the Internet Explorer instance.
                    win.LocationName = window.LocationName
                    win.Url = window.LocationURL
                    win.Hwnd = window.HWND
 
                    list.Add(win)
                End If
            Next window
            Return list
        End Function
    End Class
    Private Sub hotKey_Pressed(ByVal sender As System.Object, ByVal e As HotKeyPressedEventArgs)
 
        Dim windowList As List(Of Window) = InternetExplorerWindows.GetWindows()
        Dim activeHwnd As Integer = GetForegroundWindow()
 
        For Each win As Window In windowList
            Dim html As String = win.BodyHtml
            Dim id As String = HtmlParser.FindIntegrationID(html)
 
            If id.Length > 0 AndAlso win.Hwnd = activeHwnd Then
 
                txtPropertyValue.Text = id
 
                Dim sURL As String
                sURL = constructURL()
 
                OpenBrowser(sURL)
 
                Exit For
 
            End If
        Next win
 
    End Sub
 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
 
    Friend Class HtmlParser
 
        'This is the main logic for the PeopleSoft scrape. Parse through the HTML looking for the required data.
        ' Look for:
        ' <label for='VOUCHER_PACKSLIP_NO' class='PSEDITBOXLABEL' >Integration ID</label>
        ' </td>
        ' </tr>
        ' <tr>
        ' <td height='51' colspan='2'></td>
        ' <td colspan='4'  valign='top' align='LEFT'>
        ' <span class='PSEDITBOX_DISPONLY' >000000010001</span>
 
        Public Shared Function FindIntegrationID(ByVal pageText As String) As String
            Dim document As New mshtml.HTMLDocument()
 
            ' The HTML document class doesn't have the correct 'write' method, 
            ' so use the IHTMLDocument2 interface.
            CType(document, mshtml.IHTMLDocument2).write(pageText)
 
            Dim labelFound As Boolean = False
            Dim count As Integer = 0
 
            For Each table As mshtml.HTMLTable In document.getElementsByTagName("table")
 
                If table.className = "PSPAGECONTAINER" Then
 
                    ' Loop through all the table cells (<td> elements)
                    For Each cell As mshtml.HTMLTableCell In table.getElementsByTagName("td")
 
                        If Not labelFound Then
                            ' Look for the last 'Integration ID' label, since we need the lowest
                            ' level <td> element.
                            For Each label As mshtml.HTMLLabelElement In cell.getElementsByTagName("label")
                                If label.innerText = "Integration ID" Then
                                    If count < 4 Then
                                        count += 1
                                    Else
                                        ' The right <label> was found, so quit looking, and start looking for the next <span>.
                                        labelFound = True
                                        Exit For
                                    End If
                                End If
                            Next label
                        Else
                            ' The next element that has a <span> child should be the 'Integration ID' value.
                            For Each span As mshtml.HTMLSpanElement In cell.getElementsByTagName("span")
                                Return Format(Val(span.innerText), "000000000000")
                            Next span
                        End If
 
                    Next cell
 
                End If
 
            Next table
 
            Return ""
 
        End Function
 
    End Class
 
End Class
[+][-]04.17.2008 at 12:18PM PDT, ID: 21380407

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 12:25PM PDT, ID: 21380479

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 12:43PM PDT, ID: 21380618

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 12:55PM PDT, ID: 21380709

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 01:11PM PDT, ID: 21380855

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 01:54PM PDT, ID: 21381264

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 02:31PM PDT, ID: 21381556

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 02:49PM PDT, ID: 21381710

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 05:22PM PDT, ID: 21382482

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.18.2008 at 07:33AM PDT, ID: 21386116

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: System.UnauthorizedAccessException: Access is denied.
Sign Up Now!
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.18.2008 at 07:33AM PDT, ID: 21386125

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.18.2008 at 08:55PM PDT, ID: 21391114

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 01:52PM PDT, ID: 21405899

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 05:55PM PDT, ID: 21407415

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 06:57PM PDT, ID: 21407671

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 07:02PM PDT, ID: 21407689

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 07:08PM PDT, ID: 21407710

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 07:20PM PDT, ID: 21407750

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 07:41PM PDT, ID: 21407812

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.23.2008 at 05:23AM PDT, ID: 21419806

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 06:21AM PDT, ID: 21453675

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 07:08AM PDT, ID: 21454121

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 07:19AM PDT, ID: 21555262

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-38 / EE_QW_2_20070628