Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on a VB app in VS'10, which will open new IE browser windows various sites. In the event that the user has already opened a window to a particular resource, I don't want to open a second window - but instead, 'find' the existing one and bring that to the front. I'll have the landing page URLs (from which I can determine the primary domain) and in some cases the page title, so I can match on either of those items.

I was able to list the various open IE sessions using SHDocVw.SHellWindows, but I wasn't able to pinpoint the particular process ID in order to call Process.GetProcesses.SetForeGroundWindow(). If I rely strictly on Process.GetProcesses, I only seem to be able to find the most recently used window.

Below is the relevant part of the Sub that used SHDocVw to compare the URLs of the existing windows to the one I need to either find or launch. I unsuccessfully tried AppActivate() at one point - but I'm not sure if that's what I really wanted either.

Any comments & feedback greatly appreciated. Thank in advance

What I have tried:

Private Sub checkIE(ByVal inURL As String)

Dim blnDoNew As Boolean = True
Dim SWs As New SHDocVw.ShellWindows
Dim IE As SHDocVw.InternetExplorer
Dim strDomain As String = Replace(Replace(inURL.ToLower(), "https://", ""), "http://", "")
   strDomain = strDomain.Substring(0, (InStr(strDomain, "/") - 1))
   strDomain = strDomain.Substring(InStr(strDomain, "."))

   For Each IE In SWs
      If InStr(IE.Name, "Internet Explorer") > 0 Then
      '           Ignore empty names, and "about" and "blank", tabs:   '
         If (IE.LocationName <> "") _
               And (IE.LocationURL <> "about:Tabs") _
               And (IE.LocationURL <> "about:blank") Then
            If InStr(IE.LocationURL.ToString().ToLower(), strDomain) > 0 Then
               blnDoNew = False
               IE.Visible = True

               '   How do I find this session and pop it to the forefront?   '

            End If
         End If
      End If
   Next

   If blnDoNew Then
      openIE(inURL)
   End If
End Sub
Posted
Updated 16-Mar-18 0:34am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900