Home > Scripting > Copy Favorites folder to Home Directory

Copy Favorites folder to Home Directory

This script is designed to copy a user’s favorites folder from their local profile to their home directory. It is useful when you are not implementing roaming profiles and your users migrate to various computers in the office.

Save this script as a .vbs file, you can either incorporate it into an Active Directory Group Policy or execute the script with the cscript command.

As always this script comes with no written or implied warranty. Use at your discretion.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'Created by Dustin Berube on 1/17/2009

'This script will copy the users favorites to the users folder on the server.

Option Explicit
 
On Error Resume Next
 
Dim objShell, objFSO, objNet, strHomeShare, strUserProfile
 
'Create the shell and file system objects
Set objShell = WScript.CreateObject("WScript.Shell")
set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objNet = WScript.CreateObject("WScript.Network")
 
'Use the Shell Object to retrieve system environment variables
strHomeShare = "\\Server\Share\" & objNet.UserName
strUserProfile = objShell.SpecialFolders("Favorites") 'Local

'Exit if the variables are blank
If strHomeShare = "" Or strUserProfile = "" Then
   objShell.LogEvent 2, "Cannot copy favorites to the server" & vbCRLF & _
   "Error Description: Variables not set"
   Wscript.Quit
End If
 
If objFSO.FolderExists(strHomeShare & "\Favorites") Then
   objFSO.DeleteFolder strHomeShare & "\Favorites"
End If
 
objFSO.CopyFolder strUserProfile,strHomeShare & "\Favorites"
 
If Err Then
   objShell.LogEvent 1, "Cannot copy favorites from " & strUserProfile & _
   " to " & strHomeShare & "\Favorites" & vbCRLF & "Error Description: " & _
   Err.Description
   Err.Clear
Else
   objShell.LogEvent 0, "Favorites successfully copied from " & _
   strUserProfile & " to " & strHomeShare & "\Favorites"   
End If
 
Set objShell = Nothing
Set objFSO = Nothing
Set objNet = Nothing
Categories: Scripting Tags:
  1. No comments yet.
  1. No trackbacks yet.