UPGRADING: Any changes needes for VBS files?


Author
Message
Dustyn
Dustyn
New Member
New Member (25 reputation)New Member (25 reputation)New Member (25 reputation)New Member (25 reputation)New Member (25 reputation)New Member (25 reputation)New Member (25 reputation)New Member (25 reputation)New Member (25 reputation)
Group: Forum Members
Posts: 5, Visits: 22

Just want to make sure that the following VBS files are going to work when upgrading from V6 to V7.
When I upgraded from V5 to V6, there was an entry that needed changed... I can't remember what it was though.
Are all the commands sound in the following VBS files?

Thank you kindly,
~Dustyn~

'******************************************************************************
'*
'*
'* Module Name:    SYSTEM IMAGES.vbs
'*
'* Abstract:       This is a template VB Script file generated by Reflect v5.0
'*                 Modify to add your own functionality if required
'*
'*
'******************************************************************************

OPTION EXPLICIT

' call the main function
Call VBMain()
 

'******************************************************************************
'* Sub:     VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input:   None
'*
'* Output:  None
'*
'******************************************************************************
Sub VBMain()
 Dim objShell
 Dim ExitCode

' Elevate this script for Admin privileges in Vista
 Elevate

 Set objShell = WScript.CreateObject("WScript.Shell")

' Do the backup
 ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\Reflect.exe"" -e -w <BACKUP_TYPE> ""C:\Users\Chris\Documents\Reflect\SYSTEM IMAGES.xml"" -g")

' Copy the file(s) just created
 CopyBackupFiles ExitCode, "L:\BACKUP SYSTEM IMAGES"

' Copy the file(s) just created
 CopyBackupFiles ExitCode, "M:\BACKUP SYSTEM IMAGES"

' Copy the file(s) just created
 CopyBackupFiles ExitCode, "N:\BACKUP SYSTEM IMAGES"

' done
 Set objShell = nothing
 wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose:  Calls Reflect.exe passing an XML BDF as a parameter
'*           Optionaly logs output to file
'*
'* Input:    strCmdLine Command Line Arguments
'* Output:   Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
 Dim objShell
 Dim objExecObject
 Dim strLine
 Dim objFS
 Dim objNewFile
 Dim strLogFileName

 strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objExecObject = objShell.Exec(strCmdLine)

' Log to file
 strLogFileName = "C:\Users\Chris\Documents\Reflect\log-" & Year(Date) & "-" & Month(Date) & "-" & Day(Date) & " " & Hour(Time) & "." & Minute(Time) & "." & Second(Time) & ".txt"
 Set objFS = CreateObject("Scripting.FileSystemObject")
 Set objNewFile = objFS.OpenTextFile(strLogFileName , 8, 1)
 Do Until objExecObject.StdOut.AtEndOfStream
  strLine = objExecObject.StdOut.ReadLine()
  If Instr(strLine , "%") = 0 Then
   objNewFile.WriteLine strLine
  end if
 Loop

 objNewFile.Close
 set objFS = nothing

' Wait for the process to finish
 Do While objExecObject.Status = 0
  WScript.Sleep 100
 Loop

 if objExecObject.exitcode = 2 then
' Handle XML validation error

 elseif objExecObject.exitcode = 1 then
' Handle backup error
  objShell.LogEvent 1, "Macrium Reflect - Backup Failed"
 elseif objExecObject.exitcode = 0 then
' Everything OK
  objShell.LogEvent 0, "Macrium Reflect - Successful Backup"
 end if
 Backup = objExecObject.exitcode
 Set objExecObject = nothing
 Set objShell = nothing
End Function


'******************************************************************************
'* Sub:     Elevate
'*
'* Purpose: Elevates this script for Vista UAC.
'*          This means that only one UAC Elevation prompt is displayed and
'*          functions/programs will not fail if they require admin privileges
'*
'* Input:   None
'* Output:  None
'*
'******************************************************************************
Sub Elevate
 Dim ShellApp
 Dim objShell
 Dim objWshProcessEnv

 ' Don't elevate if run from Windows Task Scheduler
 If WScript.Arguments.Count > 0 Then
  If WScript.Arguments.Item(0) = "-s" then
     Exit Sub
  End If
 End If

 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objWshProcessEnv = objShell.Environment("PROCESS")

 If objWshProcessEnv("ELEVATED_APP") <> "True" Then
  objWshProcessEnv("ELEVATED_APP") = "True"
  Set ShellApp = CreateObject("Shell.Application")
  Call ShellApp.ShellExecute("""" &  WScript.FullName  & """", """" & WScript.ScriptFullName & """" & " " & GetBackupTypeParameter,  , "runas")
  set ShellApp = nothing
  Set objWshProcessEnv = nothing
  wscript.quit
 End If
 Set objWshProcessEnv = nothing
 Set objShell = nothing
End Sub


'******************************************************************************
'* Function: CopyBackupFiles
'*
'* Purpose:  Copies all files created by the previous backup / image
'*           to a supplied directory. Uses Macrium environment variables to
'*           determine which files to copy.
'*
'* Input:    ExitCode - The exit code of the last backup
'*           strBackupDirectory - Directory to copy to
'*
'******************************************************************************
Function CopyBackupFiles(Byval ExitCode, Byval strBackupDirectory)
    Dim objShell
    Dim objWshProcessEnv
    Dim objShellApp
    Dim objFolder
    Dim strEnvName
    Dim nFiles
    Dim Count
    Dim strEnvPrefix
    Dim strInc
    Dim strPathToCopy   
 
' Only copy files if backup was successful
 if ExitCode <> 0 Then
     Exit Function
 End If

 Const FOF_OPTION = &H0&

 Set objShell         = WScript.CreateObject("WScript.Shell")
 Set objWshProcessEnv = objShell.Environment("VOLATILE")

 
' Get the prefix for the last backup set
    strEnvPrefix = objWshProcessEnv("MACRIUM_PREFIX")
 
' Get the total number of files for the last backup set
    nFiles = CInt(objWshProcessEnv(strEnvPrefix + "_FILECOUNT"))
' Get the last increment number. Note: increment 0 is the full backup
    strInc   = objWshProcessEnv(strEnvPrefix + "_CURRENT_INCREMENT")
    for Count = 1 To nFiles
 ' Construct the environment variable name for the increment number for each file
     strEnvName = strEnvPrefix + "_INCREMENT" + CStr(Count)
 ' If file(s) are for the last increment then copy them
     if objWshProcessEnv(strEnvName) = strInc Then
        ' Construct the environment variable for the full file path
      strEnvName = strEnvPrefix + "_FILEPATH" + CStr(Count)
      strPathToCopy = objWshProcessEnv(strEnvName)
   
      set objShellApp = CreateObject("Shell.Application")
      set objFolder = objShellApp.NameSpace(strBackupDirectory)
 
         if not objFolder is nothing then
       objFolder.CopyHere strPathToCopy, FOF_OPTION
      end if
     
            set objFolder   = nothing
            set objShellApp = nothing
  End If
 Next
 
' Clean up
 Set objShell         = nothing
 Set objWshProcessEnv = nothing
End Function


'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose:  determines the backup type from command line parameter
'*           -full Full backup
'*           -inc  Incremental backup
'*           -diff Differential backup
'*
'* Input:    None
'* Output:   the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
    Dim i

    for i = 0 to Wscript.Arguments.Count - 1
        If Wscript.Arguments(i) = "-full" OR _
           Wscript.Arguments(i) = "-inc" OR _
           Wscript.Arguments(i) = "-diff" Then
            GetBackupTypeParameter = Wscript.Arguments(i)
            Exit Function
        End If
    Next

    GetBackupTypeParameter  = ""

End Function




((((( 2ND VBS FILE BELOW )))))


'******************************************************************************
'*
'*
'* Module Name:    DATA IMAGES.vbs
'*
'* Abstract:       This is a template VB Script file generated by Reflect v5.0
'*                 Modify to add your own functionality if required
'*
'*
'******************************************************************************

OPTION EXPLICIT

' call the main function
Call VBMain()
 

'******************************************************************************
'* Sub:     VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input:   None
'*
'* Output:  None
'*
'******************************************************************************
Sub VBMain()
 Dim objShell
 Dim ExitCode

' Elevate this script for Admin privileges in Vista
 Elevate

 Set objShell = WScript.CreateObject("WScript.Shell")

' Do the backup
 ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\Reflect.exe"" -e -w <BACKUP_TYPE> ""C:\Users\Chris\Documents\Reflect\DATA IMAGES.xml"" -g")

' Copy the file(s) just created
 CopyBackupFiles ExitCode, "L:\BACKUP DATA IMAGES"

' Copy the file(s) just created
 CopyBackupFiles ExitCode, "M:\BACKUP DATA IMAGES"

' Copy the file(s) just created
 CopyBackupFiles ExitCode, "N:\BACKUP DATA IMAGES"

' done
 Set objShell = nothing
 wscript.quit(ExitCode)
End Sub


'******************************************************************************
'* Function: Backup
'*
'* Purpose:  Calls Reflect.exe passing an XML BDF as a parameter
'*           Optionaly logs output to file
'*
'* Input:    strCmdLine Command Line Arguments
'* Output:   Exit Code
'*
'******************************************************************************
Function Backup(Byref strCmdLine)
 Dim objShell
 Dim objExecObject
 Dim strLine
 Dim objFS
 Dim objNewFile
 Dim strLogFileName

 strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)

' Run the backup or image
 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objExecObject = objShell.Exec(strCmdLine)

' Log to file
 strLogFileName = "C:\Users\Chris\Documents\Reflect\log-" & Year(Date) & "-" & Month(Date) & "-" & Day(Date) & " " & Hour(Time) & "." & Minute(Time) & "." & Second(Time) & ".txt"
 Set objFS = CreateObject("Scripting.FileSystemObject")
 Set objNewFile = objFS.OpenTextFile(strLogFileName , 8, 1)
 Do Until objExecObject.StdOut.AtEndOfStream
  strLine = objExecObject.StdOut.ReadLine()
  If Instr(strLine , "%") = 0 Then
   objNewFile.WriteLine strLine
  end if
 Loop

 objNewFile.Close
 set objFS = nothing

' Wait for the process to finish
 Do While objExecObject.Status = 0
  WScript.Sleep 100
 Loop

 if objExecObject.exitcode = 2 then
' Handle XML validation error

 elseif objExecObject.exitcode = 1 then
' Handle backup error
  objShell.LogEvent 1, "Macrium Reflect - Backup Failed"
 elseif objExecObject.exitcode = 0 then
' Everything OK
  objShell.LogEvent 0, "Macrium Reflect - Successful Backup"
 end if
 Backup = objExecObject.exitcode
 Set objExecObject = nothing
 Set objShell = nothing
End Function


'******************************************************************************
'* Sub:     Elevate
'*
'* Purpose: Elevates this script for Vista UAC.
'*          This means that only one UAC Elevation prompt is displayed and
'*          functions/programs will not fail if they require admin privileges
'*
'* Input:   None
'* Output:  None
'*
'******************************************************************************
Sub Elevate
 Dim ShellApp
 Dim objShell
 Dim objWshProcessEnv

 ' Don't elevate if run from Windows Task Scheduler
 If WScript.Arguments.Count > 0 Then
  If WScript.Arguments.Item(0) = "-s" then
     Exit Sub
  End If
 End If

 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objWshProcessEnv = objShell.Environment("PROCESS")

 If objWshProcessEnv("ELEVATED_APP") <> "True" Then
  objWshProcessEnv("ELEVATED_APP") = "True"
  Set ShellApp = CreateObject("Shell.Application")
  Call ShellApp.ShellExecute("""" &  WScript.FullName  & """", """" & WScript.ScriptFullName & """" & " " & GetBackupTypeParameter,  , "runas")
  set ShellApp = nothing
  Set objWshProcessEnv = nothing
  wscript.quit
 End If
 Set objWshProcessEnv = nothing
 Set objShell = nothing
End Sub


'******************************************************************************
'* Function: CopyBackupFiles
'*
'* Purpose:  Copies all files created by the previous backup / image
'*           to a supplied directory. Uses Macrium environment variables to
'*           determine which files to copy.
'*
'* Input:    ExitCode - The exit code of the last backup
'*           strBackupDirectory - Directory to copy to
'*
'******************************************************************************
Function CopyBackupFiles(Byval ExitCode, Byval strBackupDirectory)
    Dim objShell
    Dim objWshProcessEnv
    Dim objShellApp
    Dim objFolder
    Dim strEnvName
    Dim nFiles
    Dim Count
    Dim strEnvPrefix
    Dim strInc
    Dim strPathToCopy   
 
' Only copy files if backup was successful
 if ExitCode <> 0 Then
     Exit Function
 End If

 Const FOF_OPTION = &H0&

 Set objShell         = WScript.CreateObject("WScript.Shell")
 Set objWshProcessEnv = objShell.Environment("VOLATILE")

 
' Get the prefix for the last backup set
    strEnvPrefix = objWshProcessEnv("MACRIUM_PREFIX")
 
' Get the total number of files for the last backup set
    nFiles = CInt(objWshProcessEnv(strEnvPrefix + "_FILECOUNT"))
' Get the last increment number. Note: increment 0 is the full backup
    strInc   = objWshProcessEnv(strEnvPrefix + "_CURRENT_INCREMENT")
    for Count = 1 To nFiles
 ' Construct the environment variable name for the increment number for each file
     strEnvName = strEnvPrefix + "_INCREMENT" + CStr(Count)
 ' If file(s) are for the last increment then copy them
     if objWshProcessEnv(strEnvName) = strInc Then
        ' Construct the environment variable for the full file path
      strEnvName = strEnvPrefix + "_FILEPATH" + CStr(Count)
      strPathToCopy = objWshProcessEnv(strEnvName)
   
      set objShellApp = CreateObject("Shell.Application")
      set objFolder = objShellApp.NameSpace(strBackupDirectory)
 
         if not objFolder is nothing then
       objFolder.CopyHere strPathToCopy, FOF_OPTION
      end if
     
            set objFolder   = nothing
            set objShellApp = nothing
  End If
 Next
 
' Clean up
 Set objShell         = nothing
 Set objWshProcessEnv = nothing
End Function


'******************************************************************************
'* Function: GetBackupTypeParameter
'*
'* Purpose:  determines the backup type from command line parameter
'*           -full Full backup
'*           -inc  Incremental backup
'*           -diff Differential backup
'*
'* Input:    None
'* Output:   the parameter
'*
'******************************************************************************
Function GetBackupTypeParameter
    Dim i

    for i = 0 to Wscript.Arguments.Count - 1
        If Wscript.Arguments(i) = "-full" OR _
           Wscript.Arguments(i) = "-inc" OR _
           Wscript.Arguments(i) = "-diff" Then
            GetBackupTypeParameter = Wscript.Arguments(i)
            Exit Function
        End If
    Next

    GetBackupTypeParameter  = ""

End Function


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search