Andy,
Post by Andy KI tried this batch file, but the script never runs.
How do you *know* it doesn't run ? And which one ? Currently I see three
of them: the main batch script, the VBScript, and another batch script.
In case you mean the VBScript, what happens when you, as Todd Vargo
suggested, put a "wscript.echo" -line at the top of it ? Do you see the
output appear in the console window ? Do you get any error messages ?
Post by Andy KThe script by itself runs fine.
Again asssuming that you mean the VBScript here, *how* did you test that ?
Double-clicking the script ? Trying to run it from the console using
"cscript backup.vbs" ? Something else ?
I've not looked at your posted script, as you mentioned it works alright
when you tested it. I think the problem is elswhere, like either "cscript"
not being found by the OS, or "backup.vbs" not being found by the former ...
And a remark: I had to ask quite a few questions. That means that, for me,
your post lacks information. Suggestion: When posting a question try to
look at it as if you are the reader and ask yourself if he will than be able
to know what you see and have done/tried.
I also do not see anything in regard to error- and/or warning messages you
might have seen. Those are important, as they most always point a finger to
the cause of the problem.
To repeat myself, "A good question is 50% of the answer" :-)
And a hint: if executing that "Only_Two_Newest.bat" is the last thing you do
in the main batch script you can remove the "call" infront of it (which than
means you jump to the script).
Regards,
Rudy Wieser
Post by Andy KPost by R.WieserAndy,
Post by Andy KI would like to run a batch file after a script file runs.
You can do one of two things: Either call the batch-script in your VBScript,
or call the VBScript in your batch-script
For the first, see the "run" command
http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx
For the second, just call either "wscript" (gui) or "cscript" (console) with
the name of the VBScript as the argument.
Regards,
Rudy Wieser
Post by Andy KI would like to run a batch file after a script file runs.
Can I do that ?
Thanks.
Rudy,
I tried this batch file, but the script never runs.
cscript backup.vbs
call Only_Two_Newest.bat
The script by itself runs fine.
Here is the script.
'***************************************************************************
***
Post by Andy K'*
'*
'* Module Name: My Backup.vbs
'*
'* Abstract: This is a template VB Script file generated by Reflect v5.0
'* Modify to add your own functionality if required
'*
'*
'***************************************************************************
***
Post by Andy KOPTION EXPLICIT
' call the main function
Call VBMain()
'***************************************************************************
***
Post by Andy K'* Sub: VBMain
'*
'* Purpose: This is main function to start execution
'*
'* Input: None
'*
'* Output: None
'*
'***************************************************************************
***
Post by Andy KSub VBMain()
Dim objShell
Dim ExitCode
' The following function call ensures that this script only runs once a day
If HasRunToday Then
WScript.Quit
End If
Set objShell = WScript.CreateObject("WScript.Shell")
' Do the backup
ExitCode = Backup ("""C:\Program Files\Macrium\Reflect\Reflect.exe"" -e -w
<BACKUP_TYPE> ""C:\masm32\SOURCE\Reflect\My Backup.xml""")
Post by Andy K' done
Set objShell = nothing
wscript.quit(ExitCode)
End Sub
'***************************************************************************
***
Post by Andy K'* 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
'*
'***************************************************************************
***
Post by Andy KFunction Backup(Byref strCmdLine)
Dim objShell
Dim objExecObject
Dim iReturnCode
strCmdLine = Replace(strCmdLine, "<BACKUP_TYPE>", GetBackupTypeParameter)
' 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
elseif iReturnCode = 1 then
' Handle backup error
elseif iReturnCode = 0 then
' Everything OK
end if
Backup = iReturnCode
Set objShell = nothing
End Function
'***************************************************************************
***
Post by Andy K'* Function: HasRunToday
'*
'* Purpose: determines if this script has run today
'*
'*
'* Input: None
'* Output: true if has run today false otherwise
'*
'***************************************************************************
***
Post by Andy KFunction HasRunToday
Dim RegScriptKey
Dim LastRunDate
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
RegScriptKey = "HKCU\SOFTWARE\Macrium\Reflect\Scripts\dailyRun\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
'***************************************************************************
***
Post by Andy K'* 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
'*
'***************************************************************************
***
Post by Andy KFunction 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
Andy