SHDocVw.InternetExplorer在shellWindows中返回太多对象

时间:2011-09-13 17:56:00

标签: vb.net visual-studio-2008 internet-explorer shdocvw

以下代码行返回了几个InternetExplorer对象,即使我只打开了一个浏览器窗口(没有选项卡)并且只运行了一个iexplore.exe进程。我如何才能获得打开的浏览器窗口对象?

For Each ie As SHDocVw.InternetExplorer In shellWindows

1 个答案:

答案 0 :(得分:2)

这可能会有所帮助

Dim objShellWindows As New SHDocVw.ShellWindows
Dim rVal As SHDocVw.InternetExplorer
    For Each rVal In objShellWindows
        Debug.Print TypeName(rVal.Document)
        If TypeName(rVal.Document) = "HTMLDocument" Then
            If rVal.Name = "Windows Internet Explorer" Then
                rVal.Visible = False
                rVal.Visible = True
                Set ie = rVal
                ie.Quit
                Set ie = Nothing
            End If
        End If
    Next rVal