Not for the faint of heart, but this is doable if you combine a couple of tools in a Powershell scriptI think the simplest approach would be to use the Powershell Community Extensions http://pscx.codeplex.com/ for finding source junctions and creating new ones at the target. Then, use SetACL http://setacl.sf.net/ to save the ACL from the source, then restore them to the newly created junction.Should not be too many lines of code :-)
How to copy a directory with all permissions and junctions intact?
Is there any way to copy a directory with junctions in it and have it copy them as junctions, not the contents of the junction?
I'll try to make a long story short, but I just spent a few hours cleaning up after robocopy and Windows 7's hidden junctions. I have Windows 7 installed on a spare HD so I can play around with it, get used to it, test things and figure out how I want to set it up before taking the plunge and replacing XP full time.
Just as an experiment, I wanted to create a new user account, but put its user directory on another drive and use a symlink to point to it from C:\Users. I created a new user account called Test, logged in so that its home directory was created, and then logged out.
I discovered that moving or copying the files, either in explorer or a command prompt didn't move or copy the directory junctions. I then tried robocopy since it has options to copy all security, owner and auditing info. There is also an option to "copy symbolic links versus the target."
The exact command line I used was:
robocopy C:\Users\Test D:\Users /E /COPYALL /SL /R:0
First, it didn't even copy the permissions, the few files it did copy inherited the destination parent directory's permissions, and it added a strange permission which I'll get to in a minute. It didn't take long before it stopped with an error. I don't remember the error because I've rebooted several times since then, and I don't care to try again just to get the exact error message to post here.
What happened is that there is a hidden directory junction in C:\Users\Test\AppData\Local. The junctioin name is "Application Data" and it links to C:\Users\Test\AppData\Local (the same directory it's in). This caused it to keep copying the "Application Data" folder into itself until the max folder name length was exceded and it stopped.
When I tried deleting the directory, I kept getting an error that it couldn't delete the directory because it wasn't empty. I had taken full control of the directory, but I still got the error and the directory (from what I could see) was empty.
Here's where the strange permission comes in. For some reason, the copies of the "Application Data" directory were set to hidden/system, and had the Everyone group's "List folder / read data" permission set to deny, which is why I couldn't see them, even in administrator command prompt.
Once I got the permissions sorted out, I still couldn't delete the directory because the name was too long. Windows kept telling me to rename it so it was shorter and try again. I finally managed to delete it by renaming a few "Application Data" directories to "a" and then moving part of it to another directory.
Windows for home | Previous Windows versions | Files, folders, and storage
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
7 additional answers
Sort by: Most helpful
-
Anonymous
2013-11-26T21:14:29+00:00 Well there are 2 tools that I know can definitely copy user profiles easily.
One is imagex. I have used this tool many times in the past to image whole systems and restore them. I usually use the gimagex frontend.
The second which I just used yesterday is http://www.ltr-data.se/files/strarc.zip
This tool is even more versatile than imagex.
Here's the script I used to make the clone. It really should be improved so that you can pass the driveletter argument and user dir argument, but I don't have time atm.
c:
cd\
mklink /j "Documents and Settings" C:\Users
strarc -cjd:"D:\Windows" | strarc -xd:"C:\Windows"
strarc -cjd:"D:\ProgramData" | strarc -xd:"C:\ProgramData"
strarc -cjd:"D:\Program Files" | strarc -xd:"C:\Program Files"
strarc -cjd:"D:\Program Files (x86)" | strarc -xd:"C:\Program Files (x86)"
rem strarc -e:Michael\desktop,Michael\documents,Michael\downloads,Michael\music,Michael\pictures,Michael\videos -cjd:D:\Users | strarc -xd:C:\Users
BOOTSECT /nt60 C: /mbr
bcdboot c:\windows /s C:
This script will copy everything except certain directories in the user profile. I omitted them because the customer had many many gigs in those directories. So I just created new empty directories on the target.
You also want to be booted off a winpe disc to be able to run this script. It could work off of a live system, but you'd need to add some arguments. Mostly for registry backup/restore.
-
Anonymous
2010-01-08T15:20:31+00:00 For clarification for others, the option you need to use to resolve the 'looping' issue is /XJ (exclude junction points). However as Jimnms has said, it will not actually make a copy of the junction point itself. I'm not sure how / if you can do this.
-
Anonymous
2009-11-10T08:20:41+00:00 From reading the link you provided, it is just a more detailed version of doing a "robocopy /?". According to the robocopy help page, the /sec command would only copy Data, Attributes and Time stamps where the /copyall copies all of that that plus NTFS access control list (ACL), Owner information and Auditing information. I figured out though, you have to add the /b switch, then it works.
I still haven't been able to get it to copy the directory junctions as junctions rather than the contents. I don't think it is possible. The only options concerning junctions are to exclude file junctions only, directory junctions only or all junctions.
Even after sorting out the copy permissions, every time I try to make a copy of a user's directory with the /SL command, since there is a directory junction that points to itself, it copies that junction over and over. Even if I manage to hit CTRL-C before it gets too long, it sets the hidden and system flag on the directories and adds a deny everyone permission to the directories, which makes it a time consuming pain to remove them all.
-
Anonymous
2009-11-08T14:26:19+00:00 Hi jimnms,
Welcome to Microsoft Answers.
I would suggest you to use the /sec in place of /copyall in the robocopy command and check if you can get the directories with permissions and junction points intact.
Also refer to the below mentioned link for further guidance with the command -
http://technet.microsoft.com/en-us/library/cc733145%28WS.10%29.aspx
Thanks,
Hope this helps. Let us know the results.
Meghmala – Microsoft Support
Visit our Microsoft Answers Feedback Forum and let us know what you think