Hi All,
I have a script to backup only user profiles that have been modified in the last 30 days.
I would be most grateful if anyone could help me resolve or point me in the right direction as to why the script is failing, referencing line 141, char 5.
Please find the script below:
'******************************************************************************************************************
'This sample script is provided AS IS without warranty of any kind. We further disclaims all implied
'warranties including, without limitation, any implied warranties of merchantability or of fitness for a
'particular purpose. The entire risk arising out of the use or performance of this sample script remains
'with you. In no event shall we, its authors, or anyone else involved in the creation, production, or
'delivery of this script be liable for any damages whatsoever (including, without limitation, damages for
'loss of business profits, business interruption, loss of business information, or other pecuniary loss)
'arising out of the use of or inability to use this sample script, even if author has been advised of the
'possibility of such damages.
'******************************************************************************************************************
'This script will allow you to backup all the user accounts on a workstation that belong to a particular domain
'This script requires Windows Script Host 5.1 and Internet Explorer 4.0 or later
Option Explicit
'Defined Parameters
Dim strLogFile, strLocalAccount, strBackupFilePath, strBackupFile
'Script variables
Dim strComputerName, strCmdLine, intSuccess, intError, strSubkey, arrSubKeys, intErrorCount
Dim strDomain, blnDebug, blnAdditionalFiles
Dim objWshShell, objFSO, objShellApp, objAppDataFolder, objFolderItem, strError
Dim objWmiService, objReg, objWmiSID, arrExcludeList, strExcludedAccount, blnSkip
'******************************************************************************************************************
'Set variables in this section
'Enter the your domain name here
strDomain="4RECDOMAIN"
'Path to backup file location
strBackupFilePath="F:\MIGRATIONS"
'To exclude a user account from the backup add it to the arrExcludeList array
arrExcludeList=Array("ASPNET","Administrator")
'Set blnDebug to true to see debug messages
blnDebug=False
'******************************************************************************************************************
If blnDebug=false then
On Error Resume Next
End If
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const HKEY_LOCAL_MACHINE = &H80000002
Const ALL_USERS_APPLICATION_DATA = &H23&
Const APPLICATION_DATA = &H1a&
Const ERROR_FILE_NOT_FOUND = &H80070002
Const ERROR_FILE_EXISTS = &H003A
intErrorCount=0
blnAdditionalFiles=true
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShellApp = CreateObject("Shell.Application")
'Check WSH version
If not CDbl(WScript.Version)>=5.6 then
MsgBox "This script requires Windows Script Host 5.6", vbCritical, "Script Error"
WScript.Quit
End If
'Get local computer name from registry
strComputerName=objWshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName")
If strDomain="" Then
strDomain=strComputerName
Else
strDomain = UCase(strDomain)
End If
'Create a backup path using the computer name
On Error Resume Next
strBackupFilePath = strBackupFilePath & "\" & strComputerName
Dim objBackupFolder
Set objBackupFolder=objFSO.CreateFolder(strBackupFilePath)
intError=Err.number
strError=Err.Description
If Not intError=0 Then
If intError=ERROR_FILE_EXISTS Then
Err.Clear
Else
MsgBox "Could not create " & strBackupFilePath & " folder." & vbNewLine & vbNewLine _
& "Error " & strError, vbExclamation, "Transwiz Backup Script Error"
WScript.Quit
End If
End If
On Error Goto 0
'Set Log file path
strLogFile=strBackupFilePath & "\Transwiz.log"
'Get list of profiles
Set objWmiService = GetObject("winmgmts:{impersonationLevel=Impersonate}")
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\", arrSubKeys
For Each strSubkey In arrSubKeys
Set objWmiSID = objWmiService.Get("Win32_SID.SID='" & strSubkey & "'")
If Err = 0 Then
If objWmiSID.ReferencedDomainName=strDomain Then
blnSkip=false
For Each strExcludedAccount In arrExcludeList
If objWmiSID.AccountName=strExcludedAccount Then
blnSkip=true
ShowDebugMessage "Skipping profile for " & objWmiSID.ReferencedDomainName & "\" & objWmiSID.AccountName _
& vbNewLine & vbNewLine & "Account is in exclude list."
Exit For
End If
Next
If blnSkip=false Then
'Modified code to get last access time
Dim strPath, objFile, objNTUserFile, objLastAccessDate,
strPath=objWshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strSubkey & "\ProfileImagePath")
strPath = strPath + "\NTUSER.DAT"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNTUserFile = objFSO.GetFile(strPath)
ShowDebugMessage strPath & " modified: " & CDate(objNTUserFile.DateLastModified)
'Calculate the date 30 days ago
objLastAccessDate = DateAdd("d", -30, Now())
If(objNTUserFile.DateLastModified > objLastAccessDate) Then
ShowDebugMessage "Profile modified in the last 30 days."
Else
ShowDebugMessage "Profile NOT modified in the last 30 days."
blnSkip=true
End If
End If
If blnSkip=false Then
strLocalAccount=strDomain & "\" & objWmiSID.AccountName
ShowDebugMessage "Backing up profile for " & objWmiSID.ReferencedDomainName & "\" & objWmiSID.AccountName
strBackupFile=strBackupFilePath & "\" & objWmiSID.AccountName & ".trans.zip"
strCmdLine="Transwiz /BACKUP /SOURCEACCOUNT " & strLocalAccount & " /TRANSFERFILE " & strBackupFile _
& " /LOG " & strLogFile
'Backup and additional files with first profile
If blnAdditionalFiles = false Then
strCmdLine = strCmdLine & " /NOPATHS"
Else
blnAdditionalFiles = false
End If
intSuccess=1
ShowDebugMessage strCmdLine
'Special error handling for common failure
On Error Resume Next
intSuccess=objWshShell.Run (strCmdLine, 0, true)
intError=Err.number
If blnDebug=true then
On Error GoTo 0
End If
If not intError=0 Then
If intError=ERROR_FILE_NOT_FOUND Then
MsgBox "The script cannot find the Transwiz.exe file.", vbCritical, "ForensiT Script Debugging"
WScript.Quit
Else
Err.Raise intError
End If
End If
If intSuccess<>0 Then
intErrorCount=intErrorCount +1
End If
End If
End If
End If
Next
'******************************************************************************************************************
'Completion message - code in this section can be deleted
Dim strMessage
strMessage=""
If intErrorCount<>0 Then
strMessage=strMessage & CStr(intErrorCount) & " local account(s) were not backed up. See " & strLogFile& "."
MsgBox strMessage, vbExclamation, "Transwiz Backup Script"
Else
MsgBox "Backup Complete", vbInformation, "Transwiz Backup Script"
End If
'******************************************************************************************************************
'Functions
'Show Debug Message
Function ShowDebugMessage(strMessage)
If blnDebug=true Then
MsgBox strMessage, vbInformation, "ForensiT Script Debugging"
End If
End Function
_________________________________________________________________________________________
Many thanks,
Keith