Jni
Jni

Reputation: 5

VB.Net Check if a website is open in IE

I'm searching if it possible to check if some website for e.g. google.com is opened in IE. I have already this code but it was only for checking if IE is open and to close it, But it's not working.

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

Thanks for helping

Upvotes: 0

Views: 991

Answers (2)

Jni
Jni

Reputation: 5

    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

This code is in a timer.

Upvotes: 0

Ramankingdom
Ramankingdom

Reputation: 1486

Follow these steps

  1. Add Microsoft Internet Controls reference to project. It is available in COM. It will appear as SHDocVw

enter image description here

  1. Now in property explorer of SHDocVw change Embedded InterOp types to false enter image description here

  2. Save , Clean and Rebuild the project.

  3. Import SHDocVw in your code.
  4. Use below piece of code

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

Upvotes: 2

Related Questions