0

How can I Restore previous folder windows after restarting explorer.exe? I thought about saving the current folder position/folder path and retrieve/open it after the explorer restart? For example, if:

  1. “Drive/Work/Receipts” and “Drive/Private/Random” folder paths were opened in file explorer.
  2. save all these folder paths to a file.
  3. restart explorer.exe using stop-process -name explorer –force.
  4. open all the folder paths in the file.
Eyal Cohen
  • 381
  • 1
  • 14
  • Does "Restore previous folder windows at log-on" not cover this? – Tetsujin Feb 19 '23 at 11:00
  • no as I restart explorer and not re-log in. – Eyal Cohen Feb 19 '23 at 11:05
  • 1
    This is starting to feel like an [XY Problem](https://en.wikipedia.org/wiki/XY_problem) - why are you force-quitting Explorer in the first place? – Tetsujin Feb 19 '23 at 11:08
  • 1
    Yes indeed it is XY Problem, https://superuser.com/questions/1769487/windows-does-not-respect-theme-switch-done-by-registry – Eyal Cohen Feb 19 '23 at 11:13
  • I wanted to have it as powershell script. – Eyal Cohen Feb 19 '23 at 12:44
  • '@Eyal Cohen'; then convert the batch/cmd code to PowerShell. It's not hard to do that for such a short/small block. Yet, ditto for the XY scenario noted by others as this is not a PowerShell code-specific issue. It's an 'how do I do this? question. – postanote Feb 20 '23 at 03:35
  • '@Tetsujin', there are a few areas where this force ```Explorer``` restart is a thing. For example, when I am messing with demo/test systems, where I've configured the taskbar a certain way, I need to set that up the exact same way again. I just wanted to avoid building a whole image just for pinned items. So, I back them up (the files and reg keys) from one system and restore them to another, but they would not show until after a reboot, so, to avoid the reboot, restarting ```Explorer``` addressed my use case. Though I've not had a reason for a very long time to do that recently. – postanote Feb 20 '23 at 03:41
  • 1
    I started working on some code maybe around two years ago that would save and restore size, position, and state, was namespace-path aware, and could restore virtual folders, search results, Libraries, etc. Got most things working, but the window state capture was a kludge with flashing windows and I set it aside. In the interim, I became more familiar with pinvoke, so when I revisited the code a few months ago, I redid the troublesome sections the right way -- with APIs. Wrote my first Xml help file, and wrapped it up in a PSModule. Then got stuck trying to figure out GitHub! LOL! (Cont.) – Keith Miller Feb 20 '23 at 05:48
  • 1
    Will upload to OneDrive or somewhere and share a link when I get home to computer. – Keith Miller Feb 20 '23 at 05:50
  • @KeithMiller I am waiting for your script, Meanwhile I am sticking with this script https://superuser.com/questions/1700083/how-to-restart-explorer-without-losing-open-windows – Eyal Cohen Feb 20 '23 at 15:30
  • 1
    @EyalCohen: Here you go: [Save and restore Explorer Windows](https://1drv.ms/u/s!AqkRvcFO6LtjwEZGWm6KN6hBAKXJ?e=d1Sxi6). – Keith Miller Feb 21 '23 at 01:22
  • @KeithMiller thank you, can you put this as an answer instead of a comment so I can reward you and other peoppe find the answer quicker – Eyal Cohen Feb 21 '23 at 21:40
  • Yes. Please be patient! I'm legally blind and therefore work at high zppm levels that slow me down, but still pride myself on well-formatted, complete answers. I may get it done this evening, or maybe tomorrow. – Keith Miller Feb 21 '23 at 21:53

1 Answers1

1

I've written PowerShell code to save and restore most aspects of Explorer windows including:

  • Location (full shell namespace path)
  • Window size, position, and state (including FullScreen)
  • a subset of view settings including:
    • Icon mode (Tiles, Details, etc.)
    • Icon size
    • Sort column(s) and direction
    • GroupBy state
    • FolderFlags
  • Search specifications (for SearchResults folder)

Settings are saved to a custom object that can optionally be exported and saved to a file for future/repeated use of a desired layout.

The module exposes two advanced funcdtions:

PS > get-help *ExplorerWindow | ft -AutoSize -Wrap

Name                   Category Module                    Synopsis
----                   -------- ------                    --------
Get-ExplorerWindow     Function SaveRestoreExplorerWindow Captures the state of open Explorer
                                                          windows, creating a custom object for each
                                                          open window.
Restore-ExplorerWindow Function SaveRestoreExplorerWindow Opens an Explorer window to a previously
                                                          captured state.

You can peruse the help files or simply browse the output of ``Get-ExplorerWindow` to get statred...

PS keith> Get-ExplorerWindow


Title          : Quick access
IsControlPanel : False
Filter         :
ItemPath       : ::{679F85CB-0220-4080-B29B-5540CC05AAB6}
NameSpacePath  : Quick access
OpenByNSPath   : False
ViewState      : @{CurrentViewMode=Tiles; IconSize=48;
                 SortColumns=prop:System.Home.SortOrder;System.ItemNameDisplay;;
                 GroupBy=System.Home.Grouping; FolderFlags=AutoArrange, BesTfitWindow,
                 NoHeaderInAllViews, UseSearchFolder}
WinState       : @{TheaterMode=False; ShowCmd2=; WP=WINDOWPLACEMENT}

Title          : Windows PowerShell Script
IsControlPanel : False
Filter         :
ItemPath       : C:\Users\keith\AppData\Roaming\Microsoft\Windows\Libraries\Sandbox.library-ms&Window
                 s PowerShell Script
NameSpacePath  : Libraries\Sandbox\Windows PowerShell Script
OpenByNSPath   : True
ViewState      : @{CurrentViewMode=Details; IconSize=16; SortColumns=prop:-System.DateModified;;
                 GroupBy=System.Null; FolderFlags=AutoArrange, NoHeaderInAllViews, UseSearchFolder}
WinState       : @{TheaterMode=False; ShowCmd2=; WP=WINDOWPLACEMENT}

A .zip file with installation instructions can be downloaded here:

Keith Miller
  • 8,704
  • 1
  • 15
  • 28