Advertisement
duck__boy1981

Copy favourites

May 30th, 2012
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '****************************************************************************
  2. '* Script for restoring a users 'Favourites' file for Internet Explorer     *
  3. '****************************************************************************
  4.  
  5. Option Explicit
  6. Dim user_name       ' The user name of the currently logged in user
  7. Dim objNetwork      ' The network
  8. Dim objFSO      ' The File System Object
  9. Dim i, j        ' Dummies for looping
  10.  
  11. Set objNetwork = CreateObject("WScript.Network")    ' Create the network object (used for getting the username)
  12. Set objFSO = CreateObject("Scripting.FileSystemObject")' Create the FSO object
  13. user_name = objNetwork.UserName
  14.  
  15. Dim servers(3)          ' The terminal servers to action
  16. Dim old_favourites_file_path    ' The file path on a server of the old favourites file for individuals
  17. Dim old_favourites_unc      ' The full UNC path to check for an old favourites file
  18. Dim new_profile_file_path   ' The file path on a server of the new profile for individuals
  19. Dim new_profile_unc     ' The full UNC path to check for the exsistnece of
  20. Dim new_favourites_file_path    ' The file path on a server of the new favourites file for individuals
  21. Dim new_favourites_unc      ' The full UNC path to copy the favourites file to
  22. Dim server_copy_list        ' A list of the servers that a users favourites have been copied to
  23. Dim server_copy_count       ' A count of the servers that have had favourites copied to them
  24. Dim not_copied_to_all       ' The text string to display if the favourites are not copied to all servers
  25.  
  26. servers(0) = "ttsa"
  27. servers(1) = "ttsb"
  28. servers(2) = "ttsc"
  29. servers(3) = "ttsd"
  30.  
  31. old_favourites_file_path = "\d$\__OLD-PROFILES\" & user_name & "\Favorites\"
  32. new_profile_file_path = "\d$\Documents and Settings\" & user_name & "\"
  33. new_favourites_file_path = "\d$\Documents and Settings\" & user_name & "\Favorites\"
  34. server_copy_count = 0
  35.  
  36. ' For each server, copy the users old favourites (if possible)
  37. for i = 0 to UBound(servers) step 1
  38.  
  39.     ' Set the UNC paths
  40.     old_favourites_unc = "\\" & servers(i) & old_favourites_file_path
  41.     new_profile_unc = "\\" & servers(i) & new_profile_file_path
  42.     new_favourites_unc = "\\" & servers(i) & new_favourites_file_path
  43.    
  44.     ' Check to see if an old version of the favourites folder exists, and copy it if it does
  45.     if objFSO.FolderExists(old_favourites_unc) then
  46.    
  47.         ' Check to see if a new profile on this server exists, if not, no log on to that server has yet occured, so the favourites will not be copied
  48.         if objFSO.FolderExists(new_profile_unc) then
  49.            
  50.             ' Check that the favourites folder exists and create it if id does not
  51.             if not objFSO.FolderExists(new_favourites_unc) then
  52.                 objFSO.CreateFolder(new_favourites_unc)
  53.             end if
  54.            
  55.             ' Update the server copy list and the count of servers updated
  56.             server_copy_list = server_copy_list & servers(i) & VBCr
  57.             server_copy_count = server_copy_count + 1
  58.            
  59.             ' Do the magic and copy the favourites
  60.             objFSO.CopyFolder old_favourites_unc & "\*.*", new_favourites_unc, true
  61.            
  62.         end if
  63.        
  64.     end if
  65.    
  66. next
  67.  
  68. ' Output a message to the user to confirm that their favourites have been copied
  69. if server_copy_count <> 4 then
  70.     not_copied_to_all = VBCr & "Although your favourites could not be copied to all servers" & VBCr _
  71.     & "(because you have not logged on to all of them), they will be copied" & VBCr _
  72.     & "the next time you log on."
  73. end if
  74. Wscript.Echo "Your Internet Explorer Favourites have been copied to the" & VBCr _
  75. & "following servers -" & VBCr & VBCr & server_copy_list _
  76. & not_copied_to_all
  77.  
  78. '****************************************************
  79. '* Reset the objects and exit                       *
  80. '****************************************************
  81.  
  82. set objNetwork = nothing
  83. set objFSO = nothing
  84.  
  85. WScript.Quit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement