-1

I would like to know whether the Class Library of the Microsoft's Windows APi Code Pack library provides a direct way to iterate the Windows Explorer instances to retrieve the current path of the address bar of each Explorer instance, in simple words, I need to get a list with all the paths that are open by Explorer.exe instances.

This is the text which I would like to retrieve (from all running instances of explorer.exe)

enter image description here

I don't know if this is possibly using Windows API Code Pack then I do not have any code to demonstrate my progress (which is Zero), I'm just asking for information about this to procceed with a better investigation, but any kind of code example will be very appreciated.

If Windows API Code Pack can't help in the task, what alternatives I have to realize this? maybe Microsoft UI automation ?

PS: I doscovered the way to retrieve it using the interop Microsoft Internet Controls, the solution is explained in this url, but I'm really interested into learn how to do it using Windows API Code Pack

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 1
    *"a direct way to iterate the Windows Explorer instances to retrieve the current path of each instance"* and *"I need to get a list with all the paths that are open by Explorer.exe instances"* are very different questions. Explorer can have more paths open that just its working directory. This really sounds like a [XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem), can you edit your question and explain what you are trying to do that this "list of open paths" helps you solve? – Scott Chamberlain Oct 02 '14 at 17:54
  • Yes @Scott Chamberlain Maybe I didn't expressed properlly my intentions, I edited the question to add this detail: `retrieve the current path of the address bar of each Explorer instance`, My English is not very good, if it still unclear please say it, thanks for your comment – ElektroStudios Oct 02 '14 at 17:57
  • This link: http://omegacoder.com/?p=63 is dead – Nilay Vishwakarma Dec 29 '14 at 08:42

1 Answers1

2

This will get you most of the way there, First, add reference for Microsoft Shell Controls and Automation and Microsoft Internet Controls from the COM tab in Project -> References

Imports Shell32

Private exList As New List(Of String) '

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Dim exShell As New Shell

    exList.Clear()

    For Each win As ShellBrowserWindow In DirectCast(exShell.Windows, IShellWindows)
        thisPath = ""
        If TryCast(win.Document, IShellFolderViewDual) IsNot Nothing Then
            thisPath = DirectCast(win.Document, IShellFolderViewDual).FocusedItem.Path
        ElseIf TryCast(win.Document, ShellFolderView) IsNot Nothing Then
            thisPath = DirectCast(win.Document, ShellFolderView).FocusedItem.Path
        End If

        If String.IsNullOrEmpty(thisPath) = False Then
            ExplorerFiles.Add(thisPath)
        End If

    Next
End Sub

Test output:

C:\Temp\_test
M:\Books - Non Fiction\Crusades - Iron Men and Saints\01 Iron Men and Saints.mp3
G:\_Video\_Movies

Sometimes it also seems to report the first item is selected. This might be a better way

Community
  • 1
  • 1
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • This is a solution using Windows API Code Pack?, or Micosoft Shell and controls, or? Shell32 namespace is not regonized for me in Windows API Code Pack, please could you specify it?, thanks for your answer! – ElektroStudios Oct 02 '14 at 18:25
  • add reference for `Microsoft Shell Controls and Automation` from the COM tab in **Project -> References** – Ňɏssa Pøngjǣrdenlarp Oct 02 '14 at 18:28
  • Thanks, but it returns the first item inside the current directory, not the directory which is written in the addresbar, I'm testing it a little to discover if it can help to retrieve the addressbar directory, thanks – ElektroStudios Oct 02 '14 at 18:40
  • thats why I posted `most of the way` and `it seems to report the first item selected` and why I posted the link - that looks to fetch the path - I did not have time to investigate someone else's answer – Ňɏssa Pøngjǣrdenlarp Oct 02 '14 at 18:42
  • yes I read it, the SFV.Folder is the folder and the SFV.Folder.Items are the items inside the folder, I'm trying to convert the type of the SFV.Folder to the proper one to retrieve the folder url/path, thanks a lot... – ElektroStudios Oct 02 '14 at 18:45
  • Done, I will post the solution in a moment – ElektroStudios Oct 02 '14 at 18:47
  • Just one thing that I have in mind, if this can be realized using 'Shell Controls and Automation' that means can be also reproduced via Windows API Code Pack with its Folder classes and interfaces, I'm right? – ElektroStudios Oct 02 '14 at 18:48
  • maybe. there are more than one of those, so it depends – Ňɏssa Pøngjǣrdenlarp Oct 02 '14 at 18:55