VBS Script to copy files with permissions

One of our techs was pointing a bunch of users to their home directory in Active Directory by highlighting all users, and using the variable %username% at the end. Unfortunately, they accdidentally left a "j" infront of the %username%. So now every user has a j infront of their home folder name. I dumped a list of all users home directorys, and wrote a script to check for the j, then copy the contents from the folder with the j, to the folder without the j.

Everything works fine, except its not copying over the folder/file permissions. I can't seem to find an option to do that with the method I am using. I have also looked into using robocopy.exe from the resource kit, but had some issues. I think my script is much simpler, if I could only get it to copy permissions.

Here is my script:

Dim objFSO


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\scripts\users.txt", 1)

Set objShell = CreateObject("Wscript.Shell")

Do Until objTextFile.AtEndOfStream
      strHD = objTextFile.Readline

      If objFSO.FolderExists("c:\scripts\users\j"+strHD) then
            set copyHD = objFSO.GetFolder("c:\scripts\users\j"+strHD)
            copyHD.Copy("c:\scripts\users\"+strHD)
            objFSO.DeleteFolder("c:\scripts\users\j"+strHD)
      end if

Loop

If anyone has any ideas that wold be great!
colesyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

robrandonCommented:
If you rename the folder instead, and the folder is on the same drive, the permissions will remain intact.

Not sure how to copy the permissions in VB.
0
robrandonCommented:
Duh, renaming would keep it in the same location.....

If you move it to a new name, so long as it moves within the same drive it will maintain the permissions.

Anyway, maybe just rename the folder.
0
colesyAuthor Commented:
hmm I never thought about renaming.. That makes more sense. I will give that a shot.. Thanks.
0
colesyAuthor Commented:
It turns out renaming won't work. The tech already changed the home directories to be correct, so users have two folders. Some work is in the folder with a j and some in the correct one. They don't have access to the j folder.

After I realized this, I shouldn't have to worry about permissions. The folders should already have the right permissions, and I should just be able to copy the content over.
0
robrandonCommented:
Are you set then?  I'm not sure what you meant in your last paragraph.

If not, you could always migrate back to the J folder (with the correct permissions), remove the replacement non-J folder, then rename the original.

You'll have to determine which is easier, that, or somehow copying the permissions over to the new folder.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.