You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 3
Next »
For an example of a generated VBScript source file please see Example VBScript Source
To generate a VBScript file select the 'XML Definition Files' tab on the main window then right click on a file and select 'Generate a VBScript file'.
This open the VBScript Generation Options dialog:
Output
Property | Value |
---|
Directory | The folder where the source file is saved |
File name | The name of the VBscript source file. This defaults to the XML file name with a .vbs extension |
Shutdown
Show the generated code...
' Issue shutdown command
objShell.Run "shutdown -s"
Property | Value |
---|
Enable Shut Down | Select to enable this property |
Shut down | The PC will shut own at the end of the backup |
Log Off | The user will be logged out at the end of the backup |
Application Event logs
Please note that Macrium Reflect Server and Server Plus Edition includes Windows Event logging built-in.
Show the generated code...
if iReturnCode = 2 then
' Handle XML validation error
elseif iReturnCode = 1 then
' Handle backup error
objShell.LogEvent 1, "Macrium Reflect - VBScript Backup Failed"
elseif iReturnCode = 0 then
' Everything OK
objShell.LogEvent 0, "Macrium Reflect - Successful VBScript Backup"
end if
Property | Value |
---|
Write a message on success | Enable a Windows Event on successful backup |
| Enter the message text in the edit box below |
Write a message on failure | Enable a Windows Event for failed backups |
| Enter the message text in the edit box below |
Run Once a Day
Show the generated code...
' The following function call ensures that this script only runs once a day
If HasRunToday Then
WScript.Quit
End If
...........
'******************************************************************************
'* Function: HasRunToday
'*
'* Purpose: determines if this script has run today
'*
'*
'* Input: None
'* Output: true if has run today false otherwise
'*
'******************************************************************************
Function HasRunToday
Dim RegScriptKey
Dim LastRunDate
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\" & WScript.ScriptFullName & "\LastRun"
'Check if script has run today
ON ERROR RESUME NEXT
LastRunDate = objShell.RegRead(RegScriptKey)
If LastRunDate = cstr(Date) Then
HasRunToday = true
Else
objShell.RegWrite RegScriptKey, Date,"REG_SZ"
HasRunToday = false
End If
Set objShell = nothing
End Function
Property | Value |
---|
Run Once a Day | If selected, will only enable this script to run once per day. This is useful for example if you want a backup to happen at first login or shutdown. |
Run Programs
Show the generated code...
' Run program before backup
objShell.Run """C:\Users\Public\Admin\Before backup.bat""", 1, true
' Do the backup
ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\reflect.exe"" -e -w <BACKUP_TYPE> ""C:\Users\Dev\Documents\Reflect\example.xml""")
' Run program after backup
objShell.Run """C:\users\public\Admin\After backup.exe""", 1, true
Property | Value |
---|
Run a program or script at the start | Select to enable a program or script to run before the backup starts |
File name | The path and executable file name |
Parameters | Optional command line parameters for the program |
Run a program or script at the start | Select to enable a program or script to run when the backup ends |
File name | The path and executable file name |
Parameters | Optional command line parameters for the program |
Vista Elevation
Show the generated code...
Sub VBMain()
Dim objShell
Dim ExitCode
' Elevate this script for Admin privileges in Vista
Elevate
.................
'******************************************************************************
'* 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
Property | Value |
---|
Enable Elevation | If selected will enable UAC elevation for the entire script. This enables functions and programs to run outside the context of Macrium Reflect without requesting further elevation. |
Duplicate Backup File
Show the generated code...
' Copy the file(s) just created
CopyBackupFiles ExitCode, "D:\Archive"
................
'******************************************************************************
'* 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
Property | Value |
---|
Enable file copy | If enabled will copy the files from the backup to the supplied destination |
Directory | Enter the folder that you want to copy/archive your backup files to |
Show Progress Dialog | If selected will show the file copy progress otherwise the copy will be silent |
Click 'OK' to generate the VBScript source file