Jump to content

User Profile Redirection


Recommended Posts

Changelog:

2011-3-20:

- Script has been totally rewrited, now supports both attended and unattended mode, a few command line parameters added.

- Resolve the "access denied" issue while Windows Media Player Network Sharing Service was running(in most case).

- Add "/r" switch for renewing owner and security info for files and subdirectories that exist ONLY in new profile location.

2011-3-23: fix a bug that a user can't delete files when using original path instead of actual path. For example, "del c:\users\username\desktop\blah.txt" has the same effect as "del d:\users\username\desktop\blah.txt", "d:\users\username" is your new user profile location.

2011-3-26: remove the external program "sleeper.exe", the sleep function now replaced by a small trick.

2011-8-5: Bug fixed: Windows search under Seven's libraries did not function.

Due to the side effects that using "FolderLocation" setting in answer file causes (described from this KB article

), I decided to write a script with the purpose of implementing redirection of user shell folders .This script only works under Vista/Server2008/win7/R2.

post-21602-0-52648800-1301394724_thumb.j

Notes:

1. This script will totally redirect/move/migrate user/public profile directory to a new location specified, involving ntfs security info, owner, timestamps, attributes.

2. It currently only supports one-way migration, which means once the original user/public profile(created by system) has been moved to new location, there is no way to move them back.

3. To avoid unexpected problems, this script only supports migrate the following per-user shell folders within user profile: "
Desktop
", "
Documents
", "
Music
", "
Pictures
", "
Videos
", "
Favorites
", "
Downloads
", "
Contacts
", "
Links
", "
Saved Game
", "
Searches
", and public shell folders within public profile: "
Documents
", "
Downloads
", "
Music
", "
Pictures
", "
Recorded TV
", "
Videos
", "
Favorites
", "
Libraries
"(win7), "
Appdata
" and other folders are excluded.

4. To preserve backward compatibility of pre-Vista applications, all the original shell folders are now replaced with junction points that point to their new shell folders location. The entire process is seamless, system and applications are not aware of the changes.

5. This script is required to run with administrator privilege.

6. It's highly recommended to make a backup of the entire user profile (and public profile if ) at your first try.

Usage:

1. It's recommended to build the same directory structure for your new profile as the original user profile, for example, "d:\users\username" for user profile, or "d:\users\public" for public profile, which holds Documents, Favorties, Pictures, Music, Videos etc. folders in it. If "d:\users\username" or "d:\users\public" does not exist , let the script do the rest, it will create the directory structure automatically(later on you can copy your files back in new location mannually).

2. For use on a running operating system, close all running applications(especially real-time protection of anti-virus application) to avoid unexpected "access denied" issues, after script finished, restart the computer to make changes take effect.

3. For use during unattended windows setup, You must invoke the script only from OOBE configuration pass using "
Microsoft-Windows-Shell-Setup | FirstLogonCommands | SynchronousCommand
" setting, when user acount has already been created and relative profile settings have been applied in place. To ensure the script runs wiith administrator privilege (elevated command), it's recommended to use this utility called "
"

For example:
hstart /wait /runas moveshl.cmd /u:"d:\users\username" /p:"d:\users\public" /q

4. For a detailed usage, type
moveshl.cmd /help
in command prompt window.

PS: parameters are case-insensitive, and the sequence does not matter.

In what circumstance should you use the "/r" parameter:

- You have changed your system, for example, vista to win7, or win7 rtm to win7 sp1, and you intend to migrate user/public profile to a directory that is created by previous system or owned by a user on previous system.

- You intend to migrate user/public profile to a directory that does not belong to currently logged on user.

- You migrate user/public profile to a new location, then you receive "access denied" error when open files within the new location.

In other words, if the security identifier (Sid) for current user has been changed(even with the same user name), you need to use the "/r" parameter to renew the security info for the files created by previous user, otherwise you will receive "access denied" error when open such files after migration.

However, using the "/r" parameter will increase the time it takes to process, depending on the file size of the target location,
so if you are just to re-install the same version of system, and migrate the user/public profile created default by system to a directory owned by the logged on user, you don't need to specify the "/r" parameter.

Edited by Rico.JohnnY
Link to comment
Share on other sites


It's a combination of using reparse points and registry tweak, better than just resgistry tweak, which may be unrecognized by some apps and may be result in some unexpected compatibility issues, Camtasia Studio (also Snagit) is an example, it still save files under c:\users\username\Documents even if you have changed the documents path in registry. The advantage of using reparse points is that for application itself it did not know the actual path has been changed.

To clarify I didn't simply delete the shell folders, i replaced them with junction points, which could be treated as and "visual folder".

And, this is a batch script, not vbs ;)

Edited by Rico.JohnnY
Link to comment
Share on other sites

It's a combination of using reparse points and registry tweak, better than just resgistry tweak, which may be unrecognized by some apps and may be result in some unexpected compatibility issues, Camtasia Studio (also Snagit) is an example, it still save files under c:\users\username\Documents even if you have changed the documents path in registry. The advantage of using reparse points is that for application itself it did not know the actual path has been changed.

To clarify I didn't simply delete the shell folders, i replaced them with junction points, which could be treated as and "visual folder".

And, this is a batch script, not vbs ;)

i meant i use "a" vbs script not "this" sorry.

Link to comment
Share on other sites

  • 6 months later...
  • 2 weeks later...

Would this also work for folders such as appdata, local appdata, program files and programdata?

Currently not. I am considering adding support to such folders in the future , but now i need more test to ensure no side effects will arise by doing this.

Link to comment
Share on other sites

  • 1 month later...

Hi Johnny. I used your batch latest batch in an unattended install of win7 and the batch didn't work unattended. I used the following command:

hstart /wait /runas C:\!custom\moveshl.cmd /u:"d:\Users\MyUser" /p:"d:\Users\Public" /q

It couldn't find the path however, when I typed the path to myuser and profile manually, it worked without a flaw. Any ideas?

I also wanted to ask you about junctions points. Let's say i want to move program files from the drive C to D. Would one junction suffice or do I have make a junction to every system sub-folder under program files (common files for example)?

Link to comment
Share on other sites

It couldn't find the path however, when I typed the path to myuser and profile manually, it worked without a flaw. Any ideas?

Maybe the error was caused by the exclamation from the path "C:\!custom\moveshl.cmd", try renaming it and retrying.

I also wanted to ask you about junctions points. Let's say i want to move program files from the drive C to D. Would one junction suffice or do I have make a junction to every system sub-folder under program files (common files for example)?

Theoretically speaking, you only need to add junction point to the top level folder if all its sub-folders inherit permissions from its parent.

Edited by Rico.JohnnY
Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...