
Hi,welcome to MicrosoftQ&A. You can refer to the following code that I have tested.
The following code is referenced from Castorix31's C# code in the following question. https://learn.microsoft.com/en-us/answers/questions/1189369/how-can-i-get-the-edge-applications-information
Imports Interop.UIAutomationClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim hWndEdge As IntPtr = IntPtr.Zero
Dim procEdge As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("msedge")
If procEdge.Length <= 0 Then
Console.WriteLine("Microsoft Edge is not running")
Else
For Each proc As System.Diagnostics.Process In procEdge
If proc.MainWindowHandle = IntPtr.Zero Then
Continue For
Else
hWndEdge = proc.MainWindowHandle
Exit For
End If
Next
End If
If hWndEdge <> IntPtr.Zero Then
Dim pUIAutomation As IUIAutomation = New CUIAutomation()
Dim windowElement As IUIAutomationElement = pUIAutomation.ElementFromHandle(hWndEdge)
If windowElement IsNot Nothing Then
Dim elementArray As IUIAutomationElementArray = Nothing
Dim condition As IUIAutomationCondition = Nothing
condition = pUIAutomation.CreateTrueCondition()
elementArray = windowElement.FindAll(TreeScope.TreeScope_Descendants, condition)
Dim elementAddressBar As IUIAutomationElement = Nothing
If elementArray IsNot Nothing Then
Dim nNbItems As Integer = elementArray.Length
For nItem As Integer = 0 To nNbItems - 1
Dim element As IUIAutomationElement = elementArray.GetElement(nItem)
Dim sName As String = element.CurrentName
Dim sAutomationId As String = element.CurrentAutomationId
Console.WriteLine("Name : {0} - AutomationId : {1}", sName, sAutomationId)
Dim element5 As IUIAutomationElement5 = CType(element, IUIAutomationElement5)
Dim nLandmakType As Integer = element5.CurrentLandmarkType
If nLandmakType = 80004 Then
elementAddressBar = element
Exit For
End If
Next
If elementAddressBar IsNot Nothing Then
Dim pPattern As Object = Nothing
pPattern = elementAddressBar.GetCurrentPattern(10018)
If pPattern IsNot Nothing Then
Dim pLegacyIAccessiblePattern As IUIAutomationLegacyIAccessiblePattern = CType(pPattern, IUIAutomationLegacyIAccessiblePattern)
Dim sValue As String = pLegacyIAccessiblePattern.CurrentValue
MessageBox.Show(String.Format("Current URL = {0}", sValue), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
End If
End If
End If
End Sub
End Class
Best Regards.
Jiachen Li
----------
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.