[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

How do I redirect Special Folder to different locations?

Asked by dwstovall in VB Script, Active Directory, Microsoft Windows Operating Systems

Tags: Windows Settings, Vbscript, Special Folders, Folder Redirection

We are migrating to a new server and totally redesigning how we manage data.

Currently, have a "Home" drive mapped at login.  They also have a default cofiguration of "My Documents" containing "My Music" and "My Pictures".  

We created a DFS namespace "\\domain\File\Home$" which points to "\\server\D$\~Home".  We are also using ABE (Access-based Enumeration) so that users navigating to this share only see their folder.  For example, if I navigate to "\\domain\File\Home$", it will only show my folder "stovalld" ->  "\\domain\File\Home$\stovalld".  

Next, we want to use a GPO to redirect the user's "My Documents" to their network share - "\\domain\File\Home$\stovalld\My Documents".  That part is easy.  

Here's the part we are having trouble with.

We don't want to redirect the hundreds of Gigabytes of "My Music" and "My Pictures" to the new file server.  Instead, we want to make certain that those folders are redirected to a location on the local machine ("%USERPROFILE%\MyLocalData\My Music" and "%USERPROFILE%\MyLocalData\My Pictures").  Once redirected, we will create "MyMusic.lnk" and "MyPictures.lnk" links in the "My Documents" that point to the Music and Picture files (this is done to give the user a familiar reference point to their music and pictures).  I already have a script that copies the folders and creates the link files, and it also modifies the registry: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders (My Music and My Pictures) to point to the new locations.

Problem - I have to do all of the above (moving/redirecting the My Music and My Pictures to the new location on the local drive) prior to activating the GPO that redirects "My Documents" to the network share on the new file server.  Otherwise, when the user logs on and activates the GPO, if the My Music and My Pictures are still residing in the My Documents, it could take a very long time before the users sees his desktop during the first boot up.

Desire - When I activate the GPO that redirects My Documents to the network share, I want it to copy only the documents in My Documents so that initial synchronization only takes a few seconds.  If My Music and My Pictures are still a part of My Documents, it could take the better part of an hour for the intial boot and synchronization - plus we would have a whole bunch more to back up nightly, which we are not going to do.  We are keeping personal music and picture files on the local machine.

Question - How can I use the following script to make changes to the user's profile, during the user's logon, so that the user's My Music and My Pictures are moved and redirected to the new location, and then somehow process the redirection of My Documents to the network file share?  Or is this the wrong approach?
---------------------------------------------------------------
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_CURRENT_USER = &H80000001

Dim objFSO, objNetwork, objShell, objReg, strComputer, strNewMyPicLinkPath, strNewMyPicLinkTarget
Dim strOldMusicFolder, strNewMusicFolder, strOldPicFolder
Dim strNewPicFolder, strNewMyMusicLinkPath, strNewMyLinkTarget, strLocalComp
Dim intNewFolder, strUserName, strMyDocLoc, objShellLink, strComputerName
Dim ReturnVal

strLocalComp = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("wScript.Network")
Set objShell = CreateObject("wScript.Shell")
Set objReg = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strLocalComp & "\root\default:StdRegProv")

strUserName = objshell.ExpandEnvironmentStrings("%username%")
strComputerName = objshell.ExpandEnvironmentStrings("%ComputerName%")

strOldMusicFolder =     "C:\Documents and Settings\" & strUserName & "\My Documents\My Music"
strNewMusicFolder =     "C:\Documents and Settings\" & strUserName & "\MyLocalData"
strNewMyMusicLinkPath = "C:\Documents and Settings\" & strUserName & "\My Documents\MyMusic.lnk"
strNewMyMusicLinkTarget =    "C:\Documents and Settings\" & strUserName & "\MyLocalData\My Music"
strOldPicFolder =       "C:\Documents and Settings\" & strUserName & "\My Documents\My Pictures"
strNewPicFolder =       "C:\Documents and Settings\" & strUserName & "\MyLocalData"
strNewMyPicLinkPath =   "C:\Documents and Settings\" & strUserName & "\My Documents\MyPictures.lnk"
strNewMyPicLinkTarget = "C:\Documents and Settings\" & strUserName & "\MyLocalData\My Pictures"

If Not objFSO.FolderExists(strNewMusicFolder) Then
   On Error Resume Next  'We don't want things to halt the system
   objFSO.CreateFolder strNewMusicFolder
   If Err.Number <> 0 Then
      Msgbox Err.Number
      On Error GoTo 0
      Wscript.Echo VbCrLf & "Cannot create: " & strNewMusicFolder & VbCrLf & "Please Report This To Desktop Support at ext. 2157" & VbCrLf
   End If
   On Error GoTo 0
   If objFSO.FolderExists(strNewMusicFolder) Then
      objFSO.MoveFolder strOldMusicFolder, strNewMusicFolder & "\"
      If Err.Number <> 0 Then
         Msgbox Err.Number
         On Error GoTo 0
         Wscript.Echo VbCrLf & "Cannot move the folder to: " & strNewMusicFolder & VbCrLf & "Please Report This To Desktop Support at ext. 2157" & VbCrLf
      End If
   End If
End If

If Not objFSO.FolderExists(strNewPicFolder) Then
   On Error Resume Next  'We don't want things to halt the system
   objFSO.CreateFolder strNewPicFolder
   If Err.Number <> 0 Then
      Msgbox Err.Number
      On Error GoTo 0
      Wscript.Echo VbCrLf & "Cannot create: " & strNewPicFolder & VbCrLf & "Please Report This To Desktop Support at ext. 2157" & VbCrLf
   End If
   On Error GoTo 0
   If objFSO.FolderExists(strNewPicFolder) Then
      objFSO.MoveFolder strOldPicFolder, strNewPicFolder & "\"
      If Err.Number <> 0 Then
         Msgbox Err.Number
         On Error GoTo 0
         Wscript.Echo VbCrLf & "Cannot move the folder to: " & strNewPicFolder & VbCrLf & "Please Report This To Desktop Support at ext. 2157" & VbCrLf
      End If
   End If
End If

If Not objFSO.FileExists(strNewMyMusicLinkPath) Then
   set objShellLink = objShell.CreateShortcut(strNewMyMusicLinkPath)
   If Err.Number <> 0 Then
      Msgbox Err.Number
      On Error GoTo 0
      Wscript.Echo VbCrLf & "Cannot create the shortcut: " & strNewMyMusicLinkPath & VbCrLf & "Please Report This To Desktop Support at ext. 2157" & VbCrLf
   Else
      objShellLink.TargetPath = strNewMyMusicLinkTarget
      objShellLink.Description = "Link To Modified My Music Location"
      objShellLink.Save
   End If
End If

If Not objFSO.FileExists(strNewMyPicLinkPath) Then
   set objShellLink = objShell.CreateShortcut(strNewMyPicLinkPath)
   If Err.Number <> 0 Then
      Msgbox Err.Number
      On Error GoTo 0
      Wscript.Echo VbCrLf & "Cannot create the shortcut: " & strNewMyPicLinkPath & VbCrLf & "Please Report This To Desktop Support at ext. 2157" & VbCrLf
   Else
      objShellLink.TargetPath = strNewMyPicLinkTarget
      objShellLink.Description = "Link To Modified My Music Location"
      objShellLink.Save
   End If
End If


strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\"
strValueName = "My Music"
strValue = "C:\Documents and Settings\" & strUserName & "\MyLocalData\My Music"

ReturnVal = objReg.SetStringValue(HKEY_CURRENT_USER,strKeyPath,strValueName,strValue)
If (ReturnVal = 0) And (Err.Number = 0) Then
   'Nothing
Else
   Msgbox "SetMyMusicValue failed. Error = " & Err.Number
End If

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\"
strValueName = "My Pictures"
strValue = "C:\Documents and Settings\" & strUserName & "\MyLocalData\My Pictures"

ReturnVal = objReg.SetStringValue(HKEY_CURRENT_USER,strKeyPath,strValueName,strValue)
If (ReturnVal = 0) And (Err.Number = 0) Then
   'Nothing
Else
   Msgbox "SetMyPicValue failed. Error = " & Err.Number
End If




Once th  point  We want to make certain that the redirection of the   those folders to
[+][-]07/29/08 07:07 AM, ID: 22111566Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: VB Script, Active Directory, Microsoft Windows Operating Systems
Tags: Windows Settings, Vbscript, Special Folders, Folder Redirection
Sign Up Now!
Solution Provided By: MHasnain
Participating Experts: 3
Solution Grade: A
 
[+][-]07/29/08 07:24 AM, ID: 22111714Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/29/08 10:03 AM, ID: 22113422Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/29/08 10:42 AM, ID: 22113741Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/29/08 12:12 PM, ID: 22114523Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07/30/08 05:15 AM, ID: 22119623Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/30/08 07:48 AM, ID: 22120948Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/30/08 09:23 AM, ID: 22121997Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/14/08 12:13 AM, ID: 22228228Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/16/08 08:25 AM, ID: 22244337Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628