Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '****************************************************************************
- '* Script for restoring a users 'Nickname File' file for MS Outlook *
- '****************************************************************************
- Option Explicit
- Dim user_name ' The user name of the currently logged in user
- Dim objNetwork ' The network
- Dim objFSO ' The File System Object
- Dim i, j, k ' Dummies for looping
- Set objNetwork = CreateObject("WScript.Network") ' Create the network object (used for getting the username)
- Set objFSO = CreateObject("Scripting.FileSystemObject") ' Create the FSO object
- user_name = objNetwork.UserName
- Dim servers(3) ' The terminal servers to action
- ' Folder path variables
- Dim old_nicknames_file_path ' The file path of the old nicknames file for individuals
- Dim new_profile_file_path ' The file path of the new profile for individuals
- Dim new_nicknames_file_path ' The file path of the new nicknames file for individuals
- ' Mapped drive variables
- Dim drive_letters(1) ' The mapped drive letters to be used
- Dim shares(1) ' The shares that are to be mapped
- Dim location ' The server location of all shared drives
- Dim force, update_profile ' Booleans for setting options for removing mapped drives
- Dim mapped_drives ' The drives that are have been mapped
- ' Server copy variables
- Dim server_copy_list ' A list of the servers that a users nicknames files have been copied to
- Dim server_copy_count ' A count of the servers that have had nicknames files copied to them
- ' Text output variables
- Dim output_message ' The text string to display to the user after the process is complete
- Dim debug_text ' Dummy for outputting which folders exist when a user attempts to restore their nicknames files
- servers(0) = "ttsa"
- servers(1) = "ttsb"
- servers(2) = "ttsc"
- servers(3) = "ttsd"
- server_copy_count = 0
- debug_text = "Nickname files debug check for user '" & user_name & "'" & VBCr & VBCr
- ' Set the drive letters that are to be used for mapping (should match with the shared folder to be mapped)
- drive_letters(0) = "J:"
- drive_letters(1) = "K:"
- force = true ' Remove mapped drive even if still in use
- update_profile = true ' Update the users profile so that the mapping is permanently removed, not just for this session
- ' For each server, copy the users old nicknames file (if possible)
- for i = 0 to UBound(servers) step 1
- ' Set the server loaction of the shares
- location = "\\" & servers(i) & "\"
- ' Set the shares that are to be mapped (should match with the letter to be mapped) (does replicate the function of mapping the full UNC paths)
- shares(0) = location & "d$\__OLD-PROFILES"
- shares(1) = location & "d$\Documents and Settings"
- ' Map some network drives so that we can make a connection with the relevent credentials
- for j = 0 to UBound(drive_letters) step 1
- if (objFSO.DriveExists(drive_letters(j)) = true) then ' Check to see if the network drive is mapped, and remove it if it is
- objNetwork.RemoveNetworkDrive drive_letters(j), force, update_profile
- end if
- objNetwork.MapNetworkDrive drive_letters(j), shares(j), false, "{my_username}", "{my_password}"
- next
- ' Debugging
- ' Loop through all of the the drives that are mapped and add them to the debug string
- debug_text = debug_text & "Results for server '" & servers(i) & "'" & VBCr
- Set mapped_drives = objNetwork.EnumNetworkDrives
- For k = 0 To mapped_drives.Count - 1 Step 2
- For j = 0 To UBound(drive_letters) Step 1
- If UCase(drive_letters(j)) = UCase(mapped_drives.Item(k)) Then
- debug_text = debug_text & mapped_drives.Item(k) & "\ was mapped to " & mapped_drives.Item(k+1) & VBCr
- End If
- Next
- Next
- ' Set the paths to the old and new nicknames folders, and to the users new profile folder
- old_nicknames_file_path = "J:\" & user_name & "\Application Data\Microsoft\Outlook"
- new_profile_file_path = "K:\" & user_name & "\"
- new_nicknames_file_path = "K:\" & user_name & "\Application Data\Microsoft\Outlook"
- ' Check to see if an old version of the folder containing the nickname file exists
- if objFSO.FolderExists(old_nicknames_file_path) then
- ' Debugging
- debug_text = debug_text & " - Old nicknames folder exists" & VBCr
- ' Check to see if a new profile on this server exists, if not, no logon to that server has yet occured, so the nicknames file will not be copied
- if objFSO.FolderExists(new_profile_file_path) then
- ' Debugging
- debug_text = debug_text & " - A new profile exists" & VBCr
- ' Check that the folder containing the nickname file exists in the new profile
- if objFSO.FolderExists(new_nicknames_file_path) then
- ' Debugging
- debug_text = debug_text & " - New nicknames folder exists" & VBCr
- ' Check that the nicknames file exists in the users old profile and copy it across
- if objFSO.FileExists(old_nicknames_file_path & "\Outlook.NK2") then
- ' Debugging
- debug_text = debug_text & " - New nicknames file exists" & VBCr
- ' Update the server copy list and the count of servers updated
- server_copy_list = server_copy_list & servers(i) & VBCr
- server_copy_count = server_copy_count + 1
- ' Do the magic and copy the nicknames file
- objFSO.CopyFile old_nicknames_file_path & "\Outlook.NK2", new_nicknames_file_path, true
- objFSO.CopyFile old_nicknames_file_path & "\Outlook.NK2", old_nicknames_file_path & "\BACKUP_Outlook.NK2", true
- end if
- end if
- end if
- end if
- ' Debugging
- debug_text = debug_text & VBCr
- next
- ' Unmap the temporary drives that we have just mapped
- for j = 0 to UBound(drive_letters) step 1
- if (objFSO.DriveExists(drive_letters(j)) = true) then ' Check to see if the network drive is mapped, and remove it if it is
- objNetwork.RemoveNetworkDrive drive_letters(j), force, update_profile
- end if
- next
- ' Output a message to the user to confirm that their nicknames files have been copied
- if server_copy_count = 0 then ' No facourites copied as none exist on old profile
- output_message = "No nicknames files were found on your old profile, so none could be copied."
- else
- output_message = "Your Microsoft Outlook nicknames files have been copied to the" & VBCr _
- & "following servers -" & VBCr & VBCr & server_copy_list
- if server_copy_count <> 4 then ' Warn that not all nicknames files have been copied, but that they will replicate
- output_message = output_message & VBCr & "Although your nicknames files could not be copied to all servers" & VBCr _
- & "(because you have not logged on to all of them), they will be copied" & VBCr _
- & "the next time you log on."
- end if
- end if
- Wscript.Echo output_message
- Wscript.Echo debug_text
- '****************************************************
- '* Reset the objects and exit *
- '****************************************************
- set objNetwork = nothing
- set objFSO = nothing
- WScript.Quit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement