VB.Net检查网站是否在IE中打开

时间:2017-07-21 02:11:16

标签: vb.net

我正在搜索是否可以检查某个网站是否有例如google.com在IE中打开。我已经有了这个代码,但它仅用于检查IE是否已打开并关闭它,但它无效。

Dim processCollection() As Process
processCollection = Process.GetProcessesByName("iexplore.exe")

If processCollection.Count > 0 Then
   For Each process As Process In processCollection
      process.Dispose()
   Next
   Return False
Else
   MessageBox.Show("Ie is now close", "IE")
End If

感谢您的帮助

2 个答案:

答案 0 :(得分:2)

请按照以下步骤操作

  1. 将Microsoft Internet Controls引用添加到项目中。它在COM中可用。它将显示为SHDocVw
  2. enter image description here

    1. 现在,在SHDocVw的属性资源管理器中,将嵌入式InterOp类型更改为false enter image description here

    2. 保存,清理并重建项目。

    3. 在您的代码中导入SHDocVw。
    4. 使用下面的代码

      For Each ie As InternetExplorer In New ShellWindows()
      Console.WriteLine(ie.LocationURL())
      Next
      

答案 1 :(得分:0)

    Function InternetExplorerRunning()
    For Each ie As InternetExplorer In New ShellWindows()
        Dim OpenWebsite As String
        OpenWebsite = ie
        If OpenWebsite = "google.com" Then
            MsgBox("Google is open")
        End If
    Next
End Function

此代码位于计时器中。

相关问题