Get Directory Path From Explorer Window Using Window Handle

cementboot

Member
Joined
Aug 27, 2005
Messages
8
Hi,

Im trying to get the path of a directory from a Windows Explorer window. So far, I have been able to use API calls to get the handle of a foreground window and determine if it is an explorer window.

However, I cant figure out how to get the path of the directory that is currently displayed in that Explorer window.

Is this possible to do using Win32 API?

Thanks
 
Ok, to solve this problem I ended up having to do some COM interop stuff. But it works, so here is the solution I used:


Code:
Add reference to SHDocVw.dll 
Private Function EnumerateExplorerWindows(ByVal MyHwnd As Integer) As String
        Dim IEs As New SHDocVw.ShellWindows()
        Dim IE As SHDocVw.InternetExplorer

        For Each IE In IEs
            Try
                If IE.HWND = MyHwnd Then
                    Dim u As New Uri(IE.LocationURL)
                    Console.WriteLine("My Path Is: " & u.LocalPath)
                    Return u.LocalPath
                End If
            Catch ex As Exception
            End Try
        Next
End Function
 
Back
Top