get report of all open explorer windows

前端 未结 2 1402
慢半拍i
慢半拍i 2020-12-15 00:50

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 powers

相关标签:
2条回答
  • 2020-12-15 01:34

    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}

    0 讨论(0)
  • 2020-12-15 01:45

    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}}
    
    0 讨论(0)
提交回复
热议问题