reflect 6 VBS generated code/Robocopy?


Author
Message
jimdot
jimdot
New Member
New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)
Group: Forum Members
Posts: 5, Visits: 15
I have a script generated by reflect 6. I've elected to create a backup copy of 1 of my image files. Robocopy is used to make the copy & it does that just fine. However, it does it silently. How can I get it to show me the Command window while its running??

I'm NOT a VBS guy, but I can make the change if someone will just show me what to change in the VBS script generated by Reflect v6.

Thanks in advance,
Jim

Looks to me like a modification would be made in Function: SynchroniseDirectories, but, as I said I'm not a VBS guy


Drac144
Drac144
Expert
Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)
Group: Forum Members
Posts: 403, Visits: 1.4K
Could you please post a copy of the line in the script file that is causing RoboForm to be executed.  Typically there are comma separated numbers following the name of the file to be run.  The first of those numbers typically controls the display (if any) of a program window.
jimdot
jimdot
New Member
New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)
Group: Forum Members
Posts: 5, Visits: 15
I sure can. Here is the entire script that Reflect generated for me.

'******************************************************************************
'*'*
'*'*
'* Module Name:  C-Win 8.1 Pro & D-My Stuff - Daily Backup.vbs'* Module Name:  C-Win 8.1 Pro & D-My Stuff - Daily Backup.vbs
'*'*
'* Abstract:   This is a template VB Script file generated by Reflect v5.0'* Abstract:   This is a template VB Script file generated by Reflect v5.0
'*      Modify to add your own functionality if required'*      Modify to add your own functionality if required
'*'*
'*'*
'******************************************************************************'******************************************************************************
OPTION EXPLICIT
' call the main function' call the main function
Call VBMain()
'******************************************************************************'******************************************************************************
'* Sub:  VBMain'* Sub:  VBMain
'*'*
'* Purpose: This is main function to start execution '* Purpose: This is main function to start execution
'*'*
'* Input: None'* Input: None
'*'*
'* Output: None'* Output: None
'*'*
'******************************************************************************'******************************************************************************
Sub VBMain()
Dim objShell
Dim ExitCode
' Elevate this script for Admin privileges in Vista' Elevate this script for Admin privileges in Vista
Elevate
Set objShell = WScript.CreateObject("WScript.Shell")
' Do the backup' Do the backup
ExitCode = Backup ("""C:\My Programs\Tools n Utilities\Macrium Reflect Workstation 6\reflect.exe"" -e -w <BACKUP_TYPE> ""D:\App Configurations & Data\Macrium Reflect Backup Jobs\C-Win 8.1 Pro & D-My Stuff - Daily Backup.xml""")
' Copy the file(s) just created' Copy the file(s) just created
SynchroniseDirectories ExitCode, "H:\Macrium Reflect Backup Copies\Daily Backups"
' done' done
Set objShell = nothing
wscript.quit(ExitCode)
End Sub
'******************************************************************************'******************************************************************************
'* Function: Backup'* Function: Backup
'*'*
'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter'* Purpose: Calls Reflect.exe passing an XML BDF as a parameter
'*'*
'* Input:  strCmdLine Command Line Arguments'* Input:  strCmdLine Command Line Arguments
'* Output: Exit Code'* Output: Exit Code
'*'*
'******************************************************************************'******************************************************************************
Function Backup(Byref strCmdLine)
Dim objShell
Dim objExecObject
Dim iReturnCode
strCmdLine = ReplaceReplace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)
' Run the backup or image' Run the backup or image
Set objShell = WScript.CreateObject("WScript.Shell")
iReturnCode = objShell.Run(strCmdLine, 1, true)
if iReturnCode = 2 then
' Handle XML validation error ' Handle XML validation error
elseif iReturnCode = 1 then
' Handle backup error ' Handle backup error
elseif iReturnCode = 0 then
' Everything OK' Everything OK
end if
Backup = iReturnCode
Set objShell = nothing
End Function
'******************************************************************************'******************************************************************************
'* Sub:  Elevate'* Sub:  Elevate
'*'*
'* Purpose: Elevates this script for Vista UAC.'* Purpose: Elevates this script for Vista UAC.
'*    This means that only one UAC Elevation prompt is displayed and'*    This means that only one UAC Elevation prompt is displayed and
'*    functions/programs will not fail if they require admin privileges'*    functions/programs will not fail if they require admin privileges
'*'*
'* Input: None'* Input: None
'* Output: None'* Output: None
'*'*
'******************************************************************************'******************************************************************************
Sub Elevate
Dim ShellApp
Dim objShell
Dim objWshProcessEnv
' Don't elevate if run from Windows Task Scheduler' 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 = CreateObjectCreateObject("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: RobocopyExists'* Function: RobocopyExists
'*'*
'* Purpose: determines whether the program Robocopy can be called from the'* Purpose: determines whether the program Robocopy can be called from the
'*    command line.'*    command line.
'*'*
'* Input:  None'* Input:  None
'* Output: boolean - true if Robocopy exists'* Output: boolean - true if Robocopy exists
'*'*
'******************************************************************************'******************************************************************************
Function RobocopyExists()
On Error Resume Next
Dim objShell
Dim objExec
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec ("robocopy.exe", 0)
If Err.Number = 0 Then
RobocopyExists = True
Else
RobocopyExists = True  '<== used to be set to "False" JTH, changed it to always be "True"'<== used to be set to "False" JTH, changed it to always be "True"
End If
End Function
'******************************************************************************'******************************************************************************
'* Function: SynchroniseDirectories'* Function: SynchroniseDirectories
'*'*
'* Purpose: Copies all files created by the previous backup / image'* Purpose: Copies all files created by the previous backup / image
'*    to a supplied directory. Uses Macrium environment variables to'*    to a supplied directory. Uses Macrium environment variables to
'*    determine which files to copy. '*    determine which files to copy.
'*'*
'* Input:  ExitCode - The exit code of the last backup'* Input:  ExitCode - The exit code of the last backup
'*    strBackupDirectory - Directory to copy to'*    strBackupDirectory - Directory to copy to
'*'*
'******************************************************************************'******************************************************************************
Function SynchroniseDirectories(Byval ExitCode, Byval strSyncDirectory)
Dim objShell
Dim objWshProcessEnv
Dim strEnvPrefix
Dim strBackupDirectory
Dim strCmdLine
Dim iReturnCode
  Dim fs
Dim objSyncFiles
Dim objBackupDirectory
Dim objSyncDirectory
Dim objBackupFile
Dim objSyncFile
Dim strExtension
Dim dateBackupFile
Dim dateSyncFile
' Only copy files if backup was successful ' Only copy files if backup was successful
if ExitCode <> 0 Then
  Exit Function
End If
Set objShell   = WScript.CreateObject("WScript.Shell")
Set objWshProcessEnv = objShell.Environment("VOLATILE")
' Get the prefix for the last backup set' Get the prefix for the last backup set
strEnvPrefix = objWshProcessEnv("MACRIUM_PREFIX")
' Get the directory where we just created a backup' Get the directory where we just created a backup
strBackupDirectory = objWshProcessEnv(strEnvPrefix + "_DIRECTORY")
If rightright(strBackupDirectory, 1) = "\" Then strBackupDirectory = leftleft(strBackupDirectory, lenlen(strBackupDirectory)-1)
If rightright(strSyncDirectory, 1) = "\" Then strSyncDirectory = leftleft(strSyncDirectory, lenlen(strSyncDirectory)-1)
If RobocopyExists Then
  strCmdLine = "robocopy ""<SOURCE>"" ""<DESTINATION>"" *.mr* /copy:DAT /lev:0 /purge /r:0 /MT:16"
Else
' Robocopy does not exist - using xcopy' Robocopy does not exist - using xcopy
Set fs = CreateObjectCreateObject("Scripting.FilesystemObject")
Set objBackupDirectory = fs.GetFolder(strBackupDirectory)
Set objSyncDirectory = fs.GetFolder(strSyncDirectory)
For Each objSyncFile in objSyncDirectory.Files
strExtension = fs.GetExtensionName(objSyncFile)
dateSyncFile = objSyncFile.DateLastModified
If LeftLeft(strExtension,2) = "mr" Then
' Check if file has been deleted' Check if file has been deleted
If Not(fs.FileExists(strBackupDirectory+"\"+objSyncFile.name)) Then
fs.DeleteFile(objSyncFile)
Else
' Check if file has been modified' Check if file has been modified
Set objBackupFile = fs.GetFile(strBackupDirectory+"\"+objSyncFile.name)
dateBackupFile = objBackupFile.DateLastModified
If DateDiffDateDiff("m", dateBackupFile, dateSyncFile) <> 0 Then
fs.DeleteFile(objSyncFile)
End If
End If
End If
Next
strCmdLine = "xcopy ""<SOURCE>\*.mr*"" ""<DESTINATION>"" /c /d /h /i /v /y"
End If
strCmdLine = ReplaceReplace(strCmdLine,"<SOURCE>", strBackupDirectory)
strCmdLine = ReplaceReplace(strCmdLine,"<DESTINATION>", strSyncDirectory)
iReturnCode = objShell.Run(strCmdLine,0,true)
if iReturnCode <> 0 then
' Handle synchronisation error' Handle synchronisation error
else
' Everything OK' Everything OK
end if
' Clean up' Clean up
Set objShell = nothing
Set objWshProcessEnv = nothing
End Function
'******************************************************************************'******************************************************************************
'* Function: GetBackupTypeParameter'* Function: GetBackupTypeParameter
'*'*
'* Purpose: determines the backup type from command line parameter'* Purpose: determines the backup type from command line parameter
'*    -full Full backup'*    -full Full backup
'*    -inc Incremental backup'*    -inc Incremental backup
'*    -diff Differential backup'*    -diff Differential backup
'*'*
'* Input:  None'* Input:  None
'* Output: the parameter'* 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


added syntax highlighting
Edited 29 May 2015 10:10 AM by Stephen
jimdot
jimdot
New Member
New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)
Group: Forum Members
Posts: 5, Visits: 15
If RobocopyExists Then
  strCmdLine = "robocopy ""<SOURCE>"" ""<DESTINATION>"" *.mr* /copyBigGrinAT /lev:0 /purge /r:0 /MT:16"
Else


Drac144
Drac144
Expert
Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)Expert (634 reputation)
Group: Forum Members
Posts: 403, Visits: 1.4K
This is an issue with Robocopy.  The issue I was talking about was related to running a Windows program (as opposed to a command line program) in VBScript and control the window size.

However there are a couple of options you can try.  add the /tee option at the end of the line (after the/MT:16). 

You MAY also have to add: /log:<LogFile> where you have to fill in the name of the Robocopy log file. 

Not sure what the /log will do or if it is needed.  The above should write log output to a window.  Not sure if it will work without specifying a log file.  Again this is Robocopy not VBScript issue so I cannot be as helpful as I would like.

Tim Cowell
Tim Cowell
Junior Member
Junior Member (52 reputation)Junior Member (52 reputation)Junior Member (52 reputation)Junior Member (52 reputation)Junior Member (52 reputation)Junior Member (52 reputation)Junior Member (52 reputation)Junior Member (52 reputation)Junior Member (52 reputation)
Group: Forum Members
Posts: 14, Visits: 212
Back in 2013 I re-worked the v5 VBScript to use ROBOCOPY for copy to 2nd location.
The changes I did also appends the ROBOCOPY log to the MR log for checking.
It is here on the v5 support forum http://support.macrium.com/topic.asp?TOPIC_ID=6217
I can re-work this again for v6 if required.
Tim


jimdot
jimdot
New Member
New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)
Group: Forum Members
Posts: 5, Visits: 15
Thanks to all for the replies..
D4t4Junk13
D4t4Junk13
New Member
New Member (1 reputation)New Member (1 reputation)New Member (1 reputation)New Member (1 reputation)New Member (1 reputation)New Member (1 reputation)New Member (1 reputation)New Member (1 reputation)New Member (1 reputation)
Group: Forum Members
Posts: 1, Visits: 4
I registered with this forum to ask this very question as the OP "how can I get it to show me the Command window while its running?" and thankfully found this thread. 

My Robocopy execution line looks pretty much the same as posted above (Reflect V6 built it for me automatically when it generated the VBScript from my XML), but I tried the /TEE with and without /LOG:FILE option as suggested above and sadly nothing seems to work. I can see the progress of the Reflect backup and verification processes just fine, but after that completes successfully and the Robocopy folder synchronization begins, I very briefly see what appears to be a cmd.exe window pop up then it disappears (happens in milliseconds) and the copying seems to happen in the background, but there's no indication on my Taskbar or anything. The synchronization still completes fine if I let it go, but not having a status is really bothersome.

I have some very big backup images that can take a long time to copy/synchronize with my external drive. I would really like to see the cmd.exe window or something remain open as an indication that the backup folder synchronization is still in progress, otherwise I may not know and shut down Windows while the copy is still in progress and then not have a proper copy synchronized completely which could bite me later on. With Reflect having the option to automatically build that synchronization into a VBscript it is very useful, but I sort of feel the lack of any progress built into the script to go along with that is an important miss...seems like it should be essential considering we get a progress for the other tasks. I do understand robocopy is built into Windows and is not part of Reflect directly, but surely there has to be a way to do this? 

I'm definitely not a VBscript expert, but did try some other things I found through Google searches such as trying cmd.exe /K or cmd.exe /C right before robocopy, such as the following:

strCmdLine = "cmd.exe /K robocopy ""<SOURCE>"" ""<DESTINATION>"" *.mr* /copy: DAT /lev:0 /purge /r:0"

The /k flag means it "carries out the command specified by string but remains", while /c means it closes, except in my case with /k the window still opens and closes in milliseconds and ultimately keeps Reflect showing "Running" in Scheduled Backups even after the synchronization is finished. The only way to get it to show the Scheduled task as "Ready" again is to go into Task Manager and then the "Details" tab (I'm using Windows 10 Pro 64-bit) then look for "cmd.exe" and end the task and immediately Reflect updates the status.

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