Backup and Restore Folder View Settings in Windows 10  

Page 7 of 8 FirstFirst ... 5678 LastLast
  1. Brink's Avatar
    Posts : 56,207
    64-bit Windows 10 Pro for Workstations build 21354
    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. Try3's Avatar
    Posts : 7,386
    Windows 10 Home x64 Version 20H2 Build 19042.868
       #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 : 45
    Windows 10 20H2
       #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; 2 Weeks Ago at 23:23.
      My Computer

  4. Matthew Wai's Avatar
    Posts : 5,006
    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. Try3's Avatar
    Posts : 7,386
    Windows 10 Home x64 Version 20H2 Build 19042.868
       #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. Matthew Wai's Avatar
    Posts : 5,006
    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. Brink's Avatar
    Posts : 56,207
    64-bit Windows 10 Pro for Workstations build 21354
    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 : 45
    Windows 10 20H2
       #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:
    @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"
    
    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
    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
    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
    Script above updated to include the following registry key:
    HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes
    Last edited by LesFerch; 2 Weeks Ago at 23:21.
      My Computer


  9. Posts : 45
    Windows 10 20H2
       #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:
    $MyName = "Folder View Backup"
    $Host.UI.RawUI.WindowTitle = $MyName
    
    $TimeStr  = (get-date).ToString("yyyy-MM-dd-HHmm-ss")
    $BakDir   = "$env:APPDATA\WinViewBak"
    $BakFile  = "$BakDir\$TimeStr.reg"
    $TempDir  = "$env:TEMP"
    $T1       = "$TempDir\WinViewBak.tmp"
    $Bak      = $Null
    
    $R01 = '"HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU"'
    $R02 = '"HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags"'
    $R03 = '"HKCU\Software\Microsoft\Windows\Shell\BagMRU"'
    $R04 = '"HKCU\Software\Microsoft\Windows\Shell\Bags"'
    $R05 = '"HKCU\Software\Microsoft\Windows\ShellNoRoam\BagMRU"'
    $R06 = '"HKCU\Software\Microsoft\Windows\ShellNoRoam\Bags"'
    $R07 = '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CIDOpen"'
    $R08 = '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CIDSave"'
    $R09 = '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32"'
    $R10 = '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\NavPane"'
    $R11 = '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\GlobalSettings\Sizer"'
    $R12 = '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Defaults"'
    $R13 = '"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes"'
    
    Function DeleteUserKeys {
      Write-Host ''
      Reg Delete $R01 /F 2>$Null
      Reg Delete $R02 /F 2>$Null
      Reg Delete $R03 /F 2>$Null
      Reg Delete $R04 /F 2>$Null
      Reg Delete $R05 /F 2>$Null
      Reg Delete $R06 /F 2>$Null
      Reg Delete $R07 /F 2>$Null
      Reg Delete $R08 /F 2>$Null
      Reg Delete $R09 /F 2>$Null
      Reg Delete $R10 /F 2>$Null
      Reg Delete $R11 /F 2>$Null
      Reg Delete $R12 /F 2>$Null
      Reg Delete $R13 /F 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. Create a backup of current Explorer folder views"
      Write-Host "2. Restore Explorer folder views from backup file"
      Write-Host "3. 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}
    
        # Backup
        "1"{
    
          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}
    
          Write-Host ''
          Remove-Item $T1 2>$Null; Reg Export $R01 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R02 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R03 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R04 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R05 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R06 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R07 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R08 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R09 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R10 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R11 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R12 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null; Reg Export $R13 $T1 /y 2>$Null; If (Test-Path -Path $T1) {$Bak = $Bak + (Get-Content $T1 -Raw)}
          Remove-Item $T1 2>$Null
    
          If ($Bak -ne $Null) {Out-File -InputObject $Bak -filepath $BakFile}
          
          Write-Host `n'Backup complete.'`n
          Pause
        }
    
        # Restore
        "2"{
          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}
    
          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...'
          }
          $Button = $FileBrowser.ShowDialog()
          $File = $FileBrowser.FileName
          If ($Button -eq "Cancel") {Continue}
          DeleteUserKeys
          Reg Import $File
          Write-Host `n'Restore complete.'`n
          RestartExplorer
        }
    
        # Clear
        "3"{
          $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}
          }  
          DeleteUserKeys
          Write-Host `n'Clear complete.'`n
          RestartExplorer
        }
      }
    }
    Last edited by LesFerch; 1 Week Ago at 10:31.
      My Computer

  10. pepanee's Avatar
    Posts : 1,460
    Windows 10 Professional
       #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


 
Page 7 of 8 FirstFirst ... 5678 LastLast

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:23.
Find Us




Windows 10 Forums