|
On our network we are redirecting some things but not all folders. Users always start yelling about I am missing my favorites or when I type in Outlook I do not get the "names" to popup. So the script below will copy these important files to a backup location. I made everything modular because this script does some good things. 1. It will detect who the currently logged on user is. 2. It performs a file copy using the %userprofile% variable. 3. Lastly, it checks to see if a folder exists. (I know this one is not that exciting)
----------COPY EVERYTHING BELOW THIS LINE---------- 'This script will copy the users favorites folder and the N2K file to a file server. 'Created 12.20.06 By Cheyenne Harden On Error Resume Next Const OverwriteExisting = TRUE Const OverWriteFiles = TRUE strComputer = "." strDestFolder = "\\FILE_SERVER_NAME_HERE\PATH_HERE\" 'Do Not Remove the trailing backslash! strDestFolder2 = "" strDestFolder3 = "" strLocalFolder = "\Application Data\Microsoft\Outlook\" strFavorites = "\Favorites" strReplace = "" strUserName = "" 'Call Functions UserCheck() ProfileCheck() FolderCheck() CopyNK2() FolderCheck2() CopyFavorites() 'WScript.Echo "Done..." WScript.Quit 'Subs and Functions Sub CopyFavorites Set objShell = CreateObject("Wscript.Shell") strProfile = objShell.ExpandEnvironmentStrings("%userprofile%") 'Wscript.Echo strProfile Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.CopyFolder strProfile & strFavorites, strDestFolder3 , OverWriteFiles End Sub
Sub CopyNK2() Set objShell = CreateObject("Wscript.Shell") strProfile = objShell.ExpandEnvironmentStrings("%userprofile%") 'Wscript.Echo strProfile Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.CopyFile strProfile & strLocalFolder & "*.nk2" , strDestFolder2 , OverwriteExisting End Sub
Function FolderCheck() Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strDestFolder & strUserName & "\" & "Backup") Then 'WScript.Echo "Folder does exist." 'WScript.Echo strDestFolder & strUserName & "\" & "Backup" strDestFolder2 = strDestFolder & strUserName & "\" & "Backup" Else Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.CreateFolder(strDestFolder & "\" & strUserName & "\" & "Backup") strDestFolder2 = strDestFolder & strUserName & "\" & "Backup" End If End Function Function UserCheck() Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputer = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer in colComputer 'Wscript.Echo objComputer.UserName strUserName = Replace(objComputer.UserName, "YOUR_DOMAIN_HERE\", strReplace) 'Wscript.Echo strUserName Next End Function
Function FolderCheck2() Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strDestFolder & strUserName & "\" & "Backup\Favorites") Then 'WScript.Echo "Folder does exist." 'WScript.Echo strDestFolder & strUserName & "\" & "Backup" strDestFolder3 = strDestFolder & strUserName & "\" & "Backup\Favorites" Else Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.CreateFolder(strDestFolder & "\" & strUserName & "\" & "Backup\Favorites") strDestFolder3 = strDestFolder & strUserName & "\" & "Backup\Favorites" End If End Function Function ProfileCheck() Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strDestFolder & strUserName) Then 'WScript.Echo "Folder does exist." 'WScript.Echo strDestFolder & strUserName & "\" & "Backup" Else Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.CreateFolder(strDestFolder & "\" & strUserName) 'strDestFolder2 = strDestFolder & strUserName & "\" & "Backup" End If End Function ----------COPY EVERYTHING ABOVE THIS LINE----------
PLEASE MAKE SURE NO WORD WRAPPING IS HAPPENING IN YOUR SCRIPT!!! To make this script work you will need one things! 1. Run this as a LogOff script. 2. Make sure the user has write access to the destination folder. 3. Set the destination folder Here: strDestFolder = "\\FILE_SERVER_NAME_HERE\PATH_HERE\" 4. Set your Domain Here: strUserName = Replace(objComputer.UserName, "YOUR_DOMAIN_HERE\", strReplace)
This information is provided "AS IS" with no warranties expressed or implied.
|