Question:
BATCH script for changing User Shell folders?
Lucas
2019-10-08 16:19:28 UTC
I want to write a batch script that changes the default location of the User Shell folders (3D Objects, Contacts, Desktop, Documents, Downloads, Favorites, Links, Music, Pictures, Saved Games, Searches and Videos) to the D drive. It takes a lot of time to change them manually. Is it possible to write such a script at all? If so, could you please provide me with such a script or the information needed to write it myself, for example, registry keys, commands, etc.
Three answers:
Me2
2019-10-09 02:25:44 UTC
First and foremost, export the key's original content.



set "ShFlds=HKCU\SOFTWARE\Microsoft\"

set "ShFlds=%ShFlds%Windows\CurrentVersion\"

set "ShFlds=%ShFlds%Explorer\User Shell Folders"

reg export "%ShFlds%" %temp%\CuUShFolders.bkup



Then make the desired changes.  For example, to change Internet Explorer's cached files location to D:\Temporary Internet Files —



set "CachFld=D:\Temporary Internet Files"

reg add "%ShFlds%" /V Cache /T REG_EXPAND_SZ /D "%CachFld%" /F



Note that changing the location doesn't move the files.  That matters very little for the IE cache, but it may be important for the user's documents, Desktop, or other folders.  If this is the case, first save the original location, which is done by the following code.



@echo off

set "ShFlds=HKCU\SOFTWARE\Microsoft\"

set "ShFlds=%ShFlds%Windows\CurrentVersion\"

set "ShFlds=%ShFlds%Explorer\User Shell Folders"



reg query "%ShFlds%" /V "My Music"> %temp%\SaveShF.txt



::Create TAB for delimiter

set "MkTab=%temp%\~tab.js"

echo WScript.Echo("\x09")> %MkTab%

for /f "delims=" %%a in ('cscript //E:JScript //nologo "%MkTab%"') do set "tab=%%a"

del %MkTab%

set "MkTab="



For /f "tokens=1,2* delims=%tab%" %%a in (%temp%\SaveShF.txt) do if NOT "%%c"=="" Set "MyMusic=%%c"



echo Your personal music is stored in --

echo %MyMusic%
?
2019-10-08 20:56:24 UTC
On a computer where the folders are already changed, open the registry editor and navigate to



HKEY_CURRENT_USER\SOFTWARE\ Microsoft\Windows\ CurrentVersion\Explorer\ User Shell Folders



Make sure "User Shell Folders" on the left is selected, then choose "File -> Export" from the menu.

Save the file, then open it with Notepad.

Now carefully remove the lines pertaining to the other folders, so only the ones moved to D: remain, and save.



You can now run that file on another Computer.
Shruthi
2019-10-08 17:03:15 UTC
In the shell scrip itself you can mention the path to feth the current path and you can keep moving the file if you have mentioned the current path in the script.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...