I am using the following as a backup for all open folder windows when Windows crashes. It works well when I click on it in Windows File Explorer. It creates the batch file foldersession.bat that can be used for opening the folder windows again.
@echo off
title create backup of currently open folder windows
setlocal enabledelayedexpansion
powershell @^(^(New-Object -com shell.application^).Windows^(^)^).Document.Folder.Self.Path >> prevfolderpaths.txt
FOR /F "tokens=*" %%f IN (prevfolderpaths.txt) DO (
set "var=%%f"
set "firstletters=!var:~0,2!"
IF "!firstletters!" == "::" ( ECHO start shell:%%~f >> foldersession.bat) ELSE ( ECHO start "" "%%~f" >> foldersession.bat)
)
del "prevfolderpaths.txt"
For example, the created foldersession.bat looks like this:
start "" "C:\Users\sscic\Downloads"
start "" "C:\Windows\symbolic links\New folder"
start "" "C:\Users\sscic\Downloads"
The main batch file works well when I open it by clicking it. The problem is that I tried to run it with Windows Task Scheduler to make the open folder windows backup every few minutes. But it does not work. It creates no foldersession.bat.
I also tried launching it via explorer.exe with using C:\Users\sscic\explorer.exe "C:\Windows\symbolic links\New folder\foldersave.bat to no avail. It is baffling me completely.
No foldersession.bat is created when automating its execution as task.