Backup and Restore Folder View Settings in Windows 10  

Page 7 of 12 FirstFirst ... 56789 ... LastLast

  1. Posts : 68,881
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #60

    Brake4bots said:
    Hi Shawn,

    I've written a totally new version of this script with several enhancements, such as... registry keys are only listed one time in the code, backup data now goes to a single file, added a new option to just clear settings to return to Windows defaults, added a 1 second delay between stopping and starting Explorer (fixes issue where it would sometimes get stuck on a gray screen), and added a fix for fail if Desktop path contains a space. Please let me know if I should just post it here or send it to you first or whatever. I don't want to do anything that's not in keeping with protocol.

    BTW, I noticed your script was reposted without credit at TheWindowsClub. I can email the URL if you like.

    Les
    Hello Les,

    Sure, you can post the script here if you like.

    Please do send me the URL via PM or VM.
      My Computers


  2. Posts : 16,931
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #61

    Brake4bots said:
    ... added a fix for fail if Desktop path contains a space
    Les,

    Sorry. I misunderstood your post. I now realise that you are saying that your script copes with a space in the Desktop folder path [as does Brink's script].

    Why fail it? Why not just deal with it?
    - Somebody with the username Brake 4 bots would be grateful for that change.

    See my script referenced in post #41 of this thread and provided in full in Find the user Desktop folder path - PS, vbs, batch methods - TenForums

    The batch script shown there can cope with spaces and with special characters in the Desktop folder path [I have only tested it for the presence of &].
    - So somebody with the username Brake & bots would be grateful for that change.

    Denis
      My Computer


  3. Posts : 745
    Windows 10/11
       #62

    Code:
    Removed old code from here. See post further along in thread for new version.
    Hi Denis,

    In the original batch file, if you have, for example, "D:\Users\John Doe\Desktop" in the Desktop registry value, the For loop will return "D:\Users\John" in the [Desktop] variable. The code above will return the complete path with the space.

    Les
    Last edited by LesFerch; 27 Mar 2021 at 23:23.
      My Computer


  4. Posts : 7,606
    Windows 10 Home 20H2
       #63

    @Brake4bots,
    I can add some codes into your script, which will then bring up a "Browse For Folder" dialog box as long as "Folder View Backup" does not exist on the desktop. Users can then select a folder in the dialog box. Do you think it is a good idea? The dialog box looks like the ones shown under option seven in the tutorial below:

    Delete Folder in Windows 10
      My Computer


  5. Posts : 16,931
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #64

    Brake4bots said:
    In the original batch file, if you have, for example, "D:\Users\John Doe\Desktop" in the Desktop registry value, the For loop will return "D:\Users\John" in the [Desktop] variable. The code above will return the complete path with the space.
    Les,

    Thanks for posting that.

    When I extended Find the user Desktop folder path - PS, vbs, batch methods - TenForums last year to cope with spaces and ampersands, I did not appreciate that every one of my tests used a Desktop folder expressed in the form
    %UserProfile%\Desktop
    and I never tested paths containing explicitly-stated spaces and ampersands such as
    C:\Users\Tom & Jerry\Desktop
    I have now improved the batch file script in Find the user Desktop folder path - PS, vbs, batch methods - TenForums so it copes with both cases.

    Does your script cope with ampersands in the Desktop folder path?
    - There is nothing to tell Tom & Jerry to avoid using an ampersand in their UserName.
    - Whilst I have never come across a Tom & Jerry UserName, I have seen several Tom Jerry UserNames for those who deliberately wanted a single account for both individuals.
    - This might be their first computer so they would have no reason to think there was anything significant about a Tom & Jerry UserName.

    Thanks,
    Denis



    @Brink - Your script's references to the [original or relocated] Desktop folder path would also fail for those containing explicitly-stated spaces and ampersands such as
    C:\Users\Tom & Jerry\Desktop
    so you might want to use Find the user Desktop folder path - PS, vbs, batch methods - TenForums as an aid in adjusting your script.
    The changes are quite small but do affect each line of the Desktop folder path retrieval so you might want to
    - replace your entire first block of code {which would also result in having better variable names and more easily maintainable code}
    - do a global replacement of [Desktop] by DesktopFolder
      My Computer


  6. Posts : 7,606
    Windows 10 Home 20H2
       #65

    @Brink, I have modified the code at Try3's suggestion above.
    The highlighted variable %[Desktop]% (which is already used in your current script) stands for the correct desktop folder.
    Code:
    Set "+=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
    For /F "tokens=* " %%# in ('Reg Query "%+%" /V Desktop') Do (Set "#=%%#")
    Set "#=%#:*REG_EXPAND_SZ    =%"
    For /F "delims=" %%# in ('Echo "%#%"') Do (Set "#=%%#")
    Set "[Desktop]=%#:~1,-1%"
    
    echo The desktop folder is %[Desktop]%
    Pause
      My Computer


  7. Posts : 68,881
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #66

    Matthew Wai said:
    @Brink, I have modified the code at Try3's suggestion above.
    The highlighted variable %[Desktop]% (which is already used in your current script) stands for the correct desktop folder.
    Code:
    Set "+=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
    For /F "tokens=* " %%# in ('Reg Query "%+%" /V Desktop') Do (Set "#=%%#")
    Set "#=%#:*REG_EXPAND_SZ    =%"
    For /F "delims=" %%# in ('Echo "%#%"') Do (Set "#=%%#")
    Set "[Desktop]=%#:~1,-1%"
    
    echo The desktop folder is %[Desktop]%
    Pause
    Thank you Matthew. The .bat file has been updated for this.
      My Computers


  8. Posts : 745
    Windows 10/11
       #67

    Denis, Thanks for pointing out the issue with &. I have updated the code to handle both space and &. I also removed the 1 second delay between stopping and starting Explorer. It turns out the gray screen I was encountering was caused by running the script from within XYPlorer. That's a 32 bit file explorer, so not a good place to start and stop Explorer on a 64 bit system.

    Matthew, I think it's best to keep the batch file clean and simple and instead make a new version entirely in Powershell that has added bells and whistles. I'll try to post a Powershell version here by end of next week.

    Code:
    REM CMD (batch file) script that will backup and restore user Explorer view settings.
    REM For a GUI-less restore, simply go to Cmd line and run Reg Import YourSettings.reg
    REM where YourSettings.reg is the settings file captured with the backup option.
    
    @Echo Off
    
    Set MyName=Folder View Backup
    
    Set Desktop=
    Set Key="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
    For /F "Skip=2 Tokens=2*" %%A In ('Reg Query %Key% /v Desktop 2^>Nul') Do Set Desktop=%%B
    
    If Not Exist "%Desktop%" Set Desktop=%UserProfile%\Desktop
    
    Set BakD="%Desktop%\%MyName%"
    Set BakF="%Desktop%\%MyName%\%UserName%.reg"
    
    Set TmpF="%Tmp%\Tmp.reg"
    
    Set R01="HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU"
    Set R02="HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags"
    Set R03="HKCU\Software\Microsoft\Windows\Shell\BagMRU"
    Set R04="HKCU\Software\Microsoft\Windows\Shell\Bags"
    Set R05="HKCU\Software\Microsoft\Windows\ShellNoRoam\BagMRU"
    Set R06="HKCU\Software\Microsoft\Windows\ShellNoRoam\Bags"
    Set R07="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CIDOpen"
    Set R08="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CIDSave"
    Set R09="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32"
    Set R10="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\NavPane"
    Set R11="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\GlobalSettings\Sizer"
    Set R12="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Defaults"
    Set R13="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes"
    Set R14="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel"
    
    Title %MyName%
    
    :Menu
    Set Mode=
    Cls
    Echo.
    Echo 1. Create a backup of current Explorer folder views
    Echo 2. Restore Explorer folder views from backup file
    Echo 3. Clear current Explorer views and return to Windows defaults
    Echo.
    Set /P Mode=Choose option or press Enter to Exit: 
    
    If "%Mode%"=="1" Goto BakChk
    If "%Mode%"=="2" Goto ResChk
    If "%Mode%"=="3" Goto ResChk
    If "%Mode%"=="" Goto End
    Echo.
    Echo Invalid input.
    Echo.
    pause
    Goto Menu
    
    :BakChk
    IF Not Exist %BakF% Goto Backup
    Echo.
    Echo You already have a backup folder and file on your desktop.
    Echo Please move or rename the backup file and try again.
    Echo.
    pause
    Goto Menu
    
    :Backup
    If Not Exist %BakD% Mkdir %BakD% 2>Nul
    If Not Exist %BakD% Echo Unable to create backup folder. & Pause & Goto End
    Echo.
    Del %TmpF% 2>Nul & Reg Export %R01% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R02% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R03% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R04% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R05% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R06% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R07% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R08% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R09% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R10% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R11% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R12% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R13% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul & Reg Export %R14% %TmpF% /y 2>Nul & More %TmpF%>>%BakF% 2>Nul
    Del %TmpF% 2>Nul
    Echo.
    Echo Backup complete.
    Echo.
    Pause
    Goto Menu
    
    :ResChk
    If Exist %BakF% Goto Clear
    Echo.
    Echo You do not have a backup folder and file on your desktop.
    Goto %Mode%A
    
    :2A
    Echo Place the backup folder and file on your desktop and try again.
    Echo.
    pause
    Goto Menu
    
    :3A
    Echo Are you sure you want to clear settings without a backup?
    Echo.
    Set Choice=
    Set /P Choice=Enter Y to continue or Enter to return to menu 
    If /I "%Choice%"=="Y" Goto Clear
    Goto Menu
    
    :Clear
    Echo.
    Reg Delete %R01% /F 2>Nul
    Reg Delete %R02% /F 2>Nul
    Reg Delete %R03% /F 2>Nul
    Reg Delete %R04% /F 2>Nul
    Reg Delete %R05% /F 2>Nul
    Reg Delete %R06% /F 2>Nul
    Reg Delete %R07% /F 2>Nul
    Reg Delete %R08% /F 2>Nul
    Reg Delete %R09% /F 2>Nul
    Reg Delete %R10% /F 2>Nul
    Reg Delete %R11% /F 2>Nul
    Reg Delete %R12% /F 2>Nul
    Reg Delete %R13% /F 2>Nul
    Reg Delete %R14% /F 2>Nul
    Goto %Mode%B
    
    :2B
    Reg Import %BakF%
    Echo.
    Echo Restore complete.
    Goto Done
    
    :3B
    Echo.
    Echo Clear complete.
    
    :Done
    Echo.
    Echo Press Enter to restart Explorer and apply settings.
    Echo.
    Pause
    
    Taskkill /f /im explorer.exe
    Start Explorer.exe
    
    :End
    Last edited by LesFerch; 28 Jun 2021 at 09:09.
      My Computer


  9. Posts : 745
    Windows 10/11
       #68

    @Matthew Wai As promised, here is a PowerShell version of the Explorer Views Backup/Restore script. This version creates a new uniquely-named file each time the backup is run. The backup files are saved within a folder within AppData. The Restore option brings up a standard Explorer file dialog, where you can pick a file to restore or pick one or more backup files to delete (right-click for delete of course).

    Code:
    #  Powershell script that will backup and restore user Explorer view settings.
    #  For a GUI-less restore, simply go to Cmd line and run Reg Import YourSettings.reg
    #  where YourSettings.reg is the settings file captured with the backup option.
    
    $MyName = "Folder View Backup"
    $Host.UI.RawUI.WindowTitle = $MyName
    
    If ($PSVersionTable.PSVersion.Major -lt 3) {
      Write-Host `n'Powershell 3 or higher is required.'`n
      Read-Host -Prompt "Press any key to continue"
      Exit
    }
    
    $BakDir   = "$env:APPDATA\WinViewBak"
    $TimeStr  = (get-date).ToString("yyyy-MM-dd-HHmm-ss")
    $TestFile = "$PSScriptRoot\$TimeStr.txt"
    $TempDir  = "$env:TEMP"
    
    $Key = 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion'
    $Value = 'ProductName'
    $WinVer = (Get-ItemProperty -Path $Key -Name $Value).$Value.SubString(8,2)
    $WinVer = '   .' + $WinVer + '. '
    $WinVer = ($WinVer -Replace '\.',' ').Trim()
    
    Try {[io.file]::OpenWrite($TestFile).close()}
    Catch {}
    If (Test-Path -Path $TestFile) {
      Remove-Item $TestFile
      $BakDir = "$PSScriptRoot\WinViewBak"
    }
    
    Function SelectFolder {       
    
      Add-Type -AssemblyName System.Windows.Forms
    
      $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
      $FolderBrowser.Description = "Select backup folder..."
      $FolderBrowser.ShowNewFolderButton = $True
      $FolderBrowser.SelectedPath = $BakDir
    
      $Handle = $Null
      If ($WinVer -eq '10') {
        $Handle = [System.Windows.Forms.NativeWindow]::New()
        $Handle.AssignHandle([System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle)
      }
    
      $Button = $FolderBrowser.ShowDialog($Handle)
      If ($Button -eq "OK") {$BakDir = $FolderBrowser.SelectedPath}
    
      Return $BakDir
    }
    
    Function SelectFile {       
    
      Add-Type -AssemblyName System.Windows.Forms
    
      $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ 
        InitialDirectory = $BakDir 
        Filter = 'Registration Files (*.reg)|*.reg'
        Multiselect = $True
        Title = 'Select registry file to restore...'
      }
    
      $Handle = $Null
      If ($WinVer -eq '10') {
        $Handle = [System.Windows.Forms.NativeWindow]::New()
        $Handle.AssignHandle([System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle)
      }
    
      $File = ''
      $Button = $FileBrowser.ShowDialog($Handle)
      If ($Button -eq "OK") {$File = $FileBrowser.FileName}
    
      Return $File
    }
    
    $RegKeys = @(
    '"HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU"'
    '"HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags"'
    '"HKCU\Software\Microsoft\Windows\Shell\BagMRU"'
    '"HKCU\Software\Microsoft\Windows\Shell\Bags"'
    '"HKCU\Software\Microsoft\Windows\ShellNoRoam\BagMRU"'
    '"HKCU\Software\Microsoft\Windows\ShellNoRoam\Bags"'
    '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CIDOpen"'
    '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CIDSave"'
    '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32"'
    '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\NavPane"'
    '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\GlobalSettings\Sizer"'
    '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Defaults"'
    '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes"'
    '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel"'
    )
    
    Function DeleteUserKeys {
      ForEach ($Key in $RegKeys) {
        Reg Delete $Key /F 2>$Null
      }
    }
    
    Function DeleteTempFiles {
      For ($i = 0; $i -lt $RegKeys.Length; $i++) {
        Remove-Item "$TempDir\WinViewBak$i.tmp" 2>$Null
      }
    }
    
    Function RestartExplorer {
      Write-Host 'Press Enter to restart Explorer and apply settings.'`n
      Pause
      Get-process explorer | Stop-Process
      Exit
    }
    
    While($True){
    
      Clear-Host
      Write-Host ''
      Write-Host "1. Select backup folder (Current: $BakDir)"
      Write-Host "2. Create a backup of current Explorer folder views"
      Write-Host "3. Restore Explorer folder views from backup file"
      Write-Host "4. Clear current Explorer views and return to Windows defaults"
    
      $Mode = Read-Host `n'Choose option or press Enter to Exit'
    
      Switch($Mode){
      
        ""{Write-Host ''; Exit}
        
        # Folder
        "1"{
          $BakDir = SelectFolder
        }
    
        # Backup
        "2"{
    
          If (!(Test-Path -Path $BakDir)) {Mkdir $BakDir >$Null}
    
          If (-Not (Test-Path -Path $BakDir)) {Write-Host `n'Backup folder could not be created.'`n; Pause; Exit}
    
          DeleteTempFiles
          
          Write-Host ''
    
          $TimeStr  = (get-date).ToString("yyyy-MM-dd-HHmm-ss")
          $BakFile  = "$BakDir\$TimeStr.reg"
    
          For ($i = 0; $i -lt $RegKeys.Length; $i++) {
            $File = "$TempDir\WinViewBak$i.tmp"
            Reg Export $RegKeys[$i] $File /y 2>$Null
            If (Test-Path -Path $File) {$FileList = $FileList + "+$TempDir\WinViewBak$i.tmp"}
          }
    
          Cmd /c Copy $FileList.Trim('+') $BakFile >$Null 2>$Null
          
          DeleteTempFiles
          
          Write-Host `n'Backup complete.'`n
          Pause
        }
    
        # Restore
        "3"{
          If (-Not (Test-Path -Path $BakDir)) {Write-Host `n'Backup folder does not exist.'`n; Pause; Continue}
    
          $Count = (Get-ChildItem "$BakDir\*.reg" -file | Measure-Object).Count
          If ($Count -eq 0) {Write-Host `n'No reg files found in backup folder.'`n; Pause; Continue}
          
          $File = SelectFile
          If ($File -eq '') {Continue}
    
          Write-Host ''
          DeleteUserKeys
          Reg Import $File
          Write-Host `n'Restore complete.'`n
          RestartExplorer
        }
    
        # Clear
        "4"{
          $Count = 0
          If (Test-Path -Path $BakDir) {
            $Count = (Get-ChildItem "$BakDir\*.reg" -file | Measure-Object).Count
          }
          If ($Count -eq 0) {
            $Conf = Read-Host `n"Are you sure you want to clear settings without a backup?"
            if ($Conf -ne 'y') {Continue}
          }  
          Write-Host ''
          DeleteUserKeys
          Write-Host `n'Clear complete.'`n
          RestartExplorer
        }
      }
    }
    Last edited by LesFerch; 28 Jun 2021 at 09:10.
      My Computer


  10. Posts : 2,911
    Windows 10 Pro for the Bro
       #69

    So, supposedly, I have run into this problem with Windows 10:
    Fix Windows Not Remember & Save Folder Types or Folder Views Setting (Increase BagMRU Size Cache Memory Size) - Tech Journey

    There is an app that I've used in the past to clean unnecessary "leftover" folder settings still saved in the Registry (called: ShellBag AnalyZer + Cleaner). Yet using that app, multiple times in the recent past, caused all my folder settings to reset. Hence I have not been using that specific app anymore.

    Yet I came across the information posted on the link to that site (that I posted a link to), and apparently, for the past week or so, the settings of certain folders which kept resetting, no longer keep resetting anymore. Before I applied the information from that site to the Registry, I always have to use Brink's Folder Backup method to restore my last saved folder settings to fix the folder settings for the few folders' settings that kept resetting. I'm hoping that this "BagMRU Size Cache" is what my computer has been having an issue with though.

    ...so I just wanted to mention that info that I learned today. I'm assuming that it applies to this thread.
      My Computer


 

Tutorial Categories

Backup and Restore Folder View Settings in Windows 10 Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 23:51.
Find Us




Windows 10 Forums