get report of all open explorer windows
Asked Answered
U

2

8

I want to get a report of all open explorer windows titles and current paths. The current paths part of this is problem is answered here with C#, but I want this for powershell and am not sure how to adapt it. I am not sure how to bring out the window titles part of it.

Could someone please assist.

Unclench answered 10/7, 2015 at 18:32 Comment(4)
Have you tried anything in powershell? Getting any specific errors?Parris
I am have not tried anything yet. Primarily because I dont know how to use ShellWindowClass with powershell. And due to the fact that Windows explorer embeds all its processes, I cant use get-process to do anything like get-process | echo $_.mainWindowTitleUnclench
Based on Ansgar's answer: LocationName is the property containing name of the Window, as used in the task bar. Using his answer, you can see LocationName with: $app.Windows() | Select-Object LocationURL, LocationName ... LocationName works, as is, for local folders. *(Remote folders also contain the unc name in parentheses (\\Exsiccate
@MikeD: LocationName is the name of the location, which may or may not be the same as the window title; somewhat obscurely, it is the .Document.Folder.Self.Path property that contains the location's full local or UNC path.Dhyana
P
9

Sounds to me like you're looking for something like this:

$app = New-Object -COM 'Shell.Application'
$app.Windows() | Select-Object LocationURL

AFAICS the window objects don't have a title property, but you can get that information from Get-Process via the window handle ID:

function Get-WindowTitle($handle) {
  Get-Process |
    Where-Object { $_.MainWindowHandle -eq $handle } |
    Select-Object -Expand MainWindowTitle
}

$app = New-Object -COM 'Shell.Application'
$app.Windows() |
  Select-Object LocationURL, @{n='Title';e={Get-WindowTitle $_.HWND}}
Paderewski answered 10/7, 2015 at 20:11 Comment(8)
This is one more step on the process. If I am inferring properly, this give me the ShellWindowsClass part of the equation, but I also want to get the application titlebar from it. ie Titlebar LocationURL C:\dir1 file://c:/dir1 C:\dir2 file://c:/dir2 Sidenote: tested LocationName from that area, and have actually added it to my final choice, since some locations may not have a LocationURL (like Devices and printers, etc..) (sorry after multiple edits, I cant seem to get line breaks to work.)Unclench
Windows explorer has to have the information somewhere, because it is displayed in the taskbar, Unless they just do a conversion between the Location URL format nomenclature to an older standard DOS style nomenclature. PS sorry for the delay, I was off line for a few days.Unclench
guess I will settle for the half I have for now,Unclench
LocationName is the property containing name of the Window, as used in the task bar. Using what you have started, you can see this with: $app.Windows() | Select-Object LocationURL, LocationName ... LocationName works, as is, for local folders. *(Remote folders also contain the unc name in parentheses (\\unc name) which you would need to truncate.)Exsiccate
I'm trying to make this work. I tried "$app.Windows() | Select-Object LocationName", but the output only contains the Explorer Windows folder names, not the full path and folder that is displayed in the Explorer title. I tried "$app.Windows() | Select-Object LocationName ... LocationName" but that gives an error. I'm not sure how you accomplished the code formatting in a comment, but perhaps something was lost in MikeD's last comment?Vitiligo
I also tried the Get-WindowTitle function from further above. That does provide an output, but it is truncated to a column width of 5 characters: "C:..."Vitiligo
My goal is to capture the currently open set of explorer windows, and write out a CMD file with commands like: C:\WINDOWS\explorer.exe /e, "C:\open\this\folder"Vitiligo
@Vitiligo Please post a question of your own.Paderewski
D
6

Ansgar Wiechers' answer is helpful, but the title of File Explorer windows doesn't necessarily contain the full path of the location (folder) being displayed.

Somewhat obscurely, it is the .Document.Folder.Self.Path property of the window objects returned by the .Windows() method of the Shell.Application COM object that contains the full, local or UNC path.

Therefore, the following lists the full paths of all open Explorer windows:

(New-Object -ComObject 'Shell.Application').Windows() | ForEach-Object { 
  $_.Document.Folder.Self.Path 
}

Note: Special locations such as File Explorer's "Quick access" are represented by ::-prefixed GUIDs; e.g., ::{679F85CB-0220-4080-B29B-5540CC05AAB6}

Dhyana answered 9/11, 2019 at 22:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.