I have looked at the answers to similar posts, and though the question looks the same, the answers do not fulfill my needs.

What I'm trying to do is capture the list of open Windows Explorer paths through a batch file run at shutdown.

My reasons are because the setting to reopen Explorer processes upon reboot doesn't always work, especially when the computer closed in a poor state. An automated process probably wouldn't run in those circumstances either, but the list from the previous shutdown would help rebuild the open folders.

I work in PERL for parsing and DOS for scripting usually, though I've used other languages. A natural language script for what I'm trying to do would be:

a) Extract the list of running explorer.exe command lines, including those running as a sub-process.

b) Parse out the file paths into a list (PERL).

c) Save a date-stamped log file of the processes.

d) Create a batch file script by adding the explorer.exe command before the listed paths.

Step C would provide a record of what was being worked on regardless of whether the OS failed to reopen the folders.

Step D would be available should the boot process fail, and a simple click would rebuild the folders to the most recent known state.

What I've tried:

  1. Recent Folders, etc. - These lists are date dependent and do not include folders from ongoing projects even if they were reopened the previous day. The only way these folders are included is if they have been manually opened recently. Additionally, reopening the folders is an extensive manual task where a list could easily be converted into a batch file to open them in one go.

  2. Tasklist in CMD - This function serves to extract the information from the Details tab, not the Processes tab. In the case of Windows Explorer, this means each Explorer opened as its own process will display, but any Explorer windows that share a process are ignored except for the most recent. Despite the setting to always open in a new process, at least some end up in this shared state because of "open in a new window" ignoring that setting. These shared process Explorers are broken down on the Processes tab into sub-processes, each with the folder path. That information is ignored by Tasklist.

  3. I searched the registry for any storage of the list and was unable to find any. Not thrilled with setting something up that interacts with the registry on a frequent basis, but I tried everything I could think of.

  4. I did try some VB scripts I found on the Web, but could not get any of them running properly. I do not understand VB well enough to figure out why, and my attempts are now quite muddled, so I don't think posting any of them here would help. It's a path I'm willing to go down. I just haven't found anything successful and cannot program my own.

Note: I currently use the Snipping Tool to make an image of the list, but this is limited both because it's manual so dependent on remembering and because I have to manually type the folder names or browse to each in Explorer to restore the state.

Thank you for helping me find a solution. I have found many people asking (both on StackExchange and elsewhere), so this answer should prove useful for more than just my situation.

1 Answer 1


What about using powershell? Something like this to capture the open Explorer locations...

(New-Object -ComObject 'Shell.Application').Windows() | ForEach-Object { 
  • Thank you. That's exactly what I was trying to find. I never made the transition from CMD.exe to Powershell because I never had a reason to. Guess I do now. I still need to put it inside a batch file that I can set to run as part of the shutdown process, but I had stalled on the ability to get the data before any of that :).
    – Margaret
    Nov 29, 2020 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.