Windows – Batch – Reset Default Local Windows Folders (Folder Redirect)

email me

Having issues with redirected folders? Need to restore user profile folders back to their original paths?

This is a script I wrote to fix broken or stuck redirected folders. Just run in the current user security context.

NOTE: Perform profile backups, first!

 

:: MrNetTek
:: eddiejackson.net/blog
:: 6/15/2020
:: free for public use
:: free to claim as your own

@echo off
title Generate Local Folders
color 0a

:: KILL EXPLORER SHELL
taskkill /f /im explorer.exe
timeout /t 5 >nul

:: DESKTOP
if not exist "%UserProfile%\Desktop" mkdir "%UserProfile%\Desktop"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop" /t REG_SZ /d "C:\Users\%USERNAME%\Desktop" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Desktop" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Desktop" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Desktop" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Desktop" /S /D


:: DOCUMENTS
if not exist "%UserProfile%\Documents" mkdir "%UserProfile%\Documents"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal" /t REG_SZ /d "C:\Users\%USERNAME%\Documents" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{f42ee2d3-909f-4907-8871-4c22fc0bf756}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Documents" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Personal" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Documents" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Documents" /S /D


:: FAVORITES
if not exist "%UserProfile%\Favorites" mkdir "%UserProfile%\Favorites"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Favorites" /t REG_SZ /d "C:\Users\%USERNAME%\Favorites" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Favorites" /t REG_EXPAND_SZ /d %%USERPROFILE"%%\Favorites" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Favorites" /S /D


:: APPDATA
if not exist "%UserProfile%\AppData\Roaming" mkdir "%UserProfile%\AppData\Roaming"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "AppData" /t REG_SZ /d "C:\Users\%USERNAME%\AppData\Roaming" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "AppData" /t REG_EXPAND_SZ /d %%USERPROFILE"%%\AppData\Roaming" /f /reg:64
attrib +r -s -h "%USERPROFILE%\AppData\Roaming" /S /D


:: VIDEOS
if not exist "%UserProfile%\Videos" mkdir "%UserProfile%\Videos"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Video" /t REG_SZ /d "C:\Users\%USERNAME%\Videos" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{35286A68-3C57-41A1-BBB1-0EAE73D76C95}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Videos" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Video" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Videos" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Videos" /S /D


:: PICTURES
if not exist "%UserProfile%\Pictures" mkdir "%UserProfile%\Pictures"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Pictures" /t REG_SZ /d "C:\Users\%USERNAME%\Pictures" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{0DDD015D-B06C-45D5-8C4C-F59713854639}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Pictures" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Pictures" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Pictures" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Pictures" /S /D


:: MUSIC
if not exist "%UserProfile%\Music" mkdir "%UserProfile%\Music"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Music" /t REG_SZ /d "C:\Users\%USERNAME%\Music" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{A0C69A99-21C8-4671-8703-7934162FCF1D}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Music" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Music" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Music" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Music" /S /D


:: CONTACTS
if not exist "%UserProfile%\Contacts" mkdir "%UserProfile%\Contacts"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "{56784854-C6CB-462B-8169-88E350ACB882}" /t REG_SZ /d "C:\Users\%USERNAME%\Contacts" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{56784854-C6CB-462B-8169-88E350ACB882}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Contacts" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Contacts" /S /D


:: DOWNLOADS
if not exist "%UserProfile%\Downloads" mkdir "%UserProfile%\Downloads"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "{374DE290-123F-4565-9164-39C4925E467B}" /t REG_SZ /d "C:\Users\%USERNAME%\Downloads" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{374DE290-123F-4565-9164-39C4925E467B}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Downloads" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{7D83EE9B-2244-4E70-B1F5-5393042AF1E4}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Downloads" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Downloads" /S /D


:: LINKS
if not exist "%UserProfile%\Links" mkdir "%UserProfile%\Links"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}" /t REG_SZ /d "C:\Users\%USERNAME%\Links" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Links" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Links" /S /D


:: SEARCHES
if not exist "%UserProfile%\Searches" mkdir "%UserProfile%\Searches"
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}" /t REG_SZ /d "C:\Users\%USERNAME%\Searches" /f /reg:64
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}" /t REG_EXPAND_SZ /d %%USERPROFILE%%"\Searches" /f /reg:64
attrib +r -s -h "%USERPROFILE%\Searches" /S /D


:: CLEAR QUICK ACCESS
del /F /Q "%APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations\*"


:: RELOAD EXPLORER SHELL
timeout /t 5 >nul
start "" explorer.exe

Exit /b 0

 
tags: folder redirect, folder redirection, roaming