Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IHTMLWindow2 Access Denied (MSHTML)

270 views
Skip to first unread message

Aaron Collver

unread,
Mar 20, 2003, 10:05:10 PM3/20/03
to
I am using VB.NET parse through HTML pages and am having trouble with
frames. I can get access to the IHTMLWindow2 object for each frame, but each
time I try to access the document member I get an access denied message. I
have read Microsoft Knowledge Base Article - 196340 about getting the object
model of an HTML frame, but I unsure how to apply this knowledge in VB.NET
(or any .NET language).

Thanks for any help,

Aaron


Vadim Melnik

unread,
Mar 20, 2003, 10:43:20 PM3/20/03
to
Hi Aaron,

As far as I can understand you have a problem with using IOleContainer in
CLR. If so here is interesting link [1]. There is "comsupport.cs" file
containing definition for IOleContainer interface. Hope it will help.

[1] http://www.itwriting.com/htmleditor/index.php


--
Best regards,
Vadim Melnik
_____________________
http://www.docsultant.com/


Aaron Collver

unread,
Mar 21, 2003, 2:22:14 AM3/21/03
to
Thank you for your reply. I've spent quite a few frustrating hours trying to
translate the code in Microsoft Knowledge Base Article - 196340 to VB.NET
(or another .NET language) and have so far been unsuccessful. Apparently,
using MSHTML, frames can be accessed if they are in the same domain.
However, an application that automates Internet Explorer and grabs the
information from a web page won't work if the frames access information from
different domains. At this point I'm not even receiving an "Access is
Denied" error message - the code just mysteriously quits executing (when the
frames access information from different domains). Any help would be greatly
appreciated.

Thanks,
Aaron

-- Code snippet --
Dim Frames As IHTMLElementCollection = CType(Document,
IHTMLDocument3).getElementsByTagName("FRAME")
For Each Element In Frames
If TypeOf Element Is HTMLFrameElement Then
Dim Frame As HTMLFrameElement = CType(Element, HTMLFrameElement)
If TypeOf Frame.contentWindow Is IHTMLWindow2 Then
If TypeOf Frame.contentWindow.document Is IHTMLDocument3
Then
DocumentComplete(CType(Frame.contentWindow.document,
IHTMLDocument3))
End If
End If
End If
Next


Kushan Ratnayake

unread,
Mar 21, 2003, 3:06:49 AM3/21/03
to
Hi,
Code here is a conversion of the code in KB article in to VB.NET. It
lists the frame urls.

Dim pContainer As IOleContainer
Dim pEnumerator As IEnumUnknown
Dim pUnk As IUnknown
Dim pBrowser As SHDocVw.IWebBrowser2

pContainer = wb
' Get an enumerator for the frames
If pContainer.EnumObjects(OLECONTF.OLECONTF_EMBEDDINGS, pEnumerator) = 0
Then
pContainer = Nothing
Dim pceltFetched As Integer = 0
' Enumerate and refresh all the frames
Do While pEnumerator.Next(1, pUnk, pceltFetched) = 0
Try
If IsNothing(pUnk) Then
Exit Do
End If
' Get the IWebBrowser2 interface
pBrowser = pUnk
Debug.WriteLine("Frame: " & pBrowser.LocationURL)
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
pceltFetched = 0
Loop
pEnumerator = Nothing
End If

regards
Kushan Ratnayake

"Aaron Collver" <aaron_...@hotmail.com> wrote in message
news:utiyZq37...@TK2MSFTNGP10.phx.gbl...

Aaron Collver

unread,
Mar 21, 2003, 2:37:55 PM3/21/03
to
I've found a solution that is much simpler for accessing frames. The catch
is I have to store the InternetExplorer or the Document object to able to
work with them later. Apparently the reason for this is frame to frame
security - a script shouldn't be able to access frames from other domains
that might contain passwords, credit card numbers and other sensitive
information.

Private Sub Browser__DocumentComplete(ByVal pDisp As Object, ByRef URL As
Object) Handles Browser_.DocumentComplete
If TypeOf pDisp Is InternetExplorer Then
With CType(pDisp, InternetExplorer).Document
'Code goes here
End With
End If
End Sub

Aaron

"Kushan Ratnayake" <nos...@invalid.com> wrote in message
news:eoaUZE47...@TK2MSFTNGP10.phx.gbl...

Aaron Collver

unread,
Mar 21, 2003, 6:51:55 PM3/21/03
to
I'm close to finishing a class that encapsulates an instance of
InternetExplorer and keeps track of the different frames and makes them
available through the class interface. This class overcomes the problem of
determining when a window has been closed (each frame has its own window
object). Anyone interested in obtaining source code or a .NET library should
contact me.

Aaron


0 new messages