Discussion:
Run a batch file after script runs
(too old to reply)
Andy K
2015-01-14 04:21:48 UTC
Permalink
I would like to run a batch file after a script file runs.

Can I do that ?

Thanks.
R.Wieser
2015-01-14 08:59:38 UTC
Permalink
Andy,
Post by Andy K
I 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 K
I would like to run a batch file after a script file runs.
Can I do that ?
Thanks.
Andy K
2015-01-16 03:19:48 UTC
Permalink
Post by R.Wieser
Andy,
Post by Andy K
I 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 K
I 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.

'******************************************************************************
'*
'*
'* 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
'*
'*
'******************************************************************************

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

' 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""")

' 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 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

'******************************************************************************
'* 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\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


'******************************************************************************
'* 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


Andy
Todd Vargo
2015-01-16 04:28:51 UTC
Permalink
Post by Andy K
Post by R.Wieser
Andy,
Post by Andy K
I 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 K
I 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.
<snip>

I already provided you with a debugging suggestion in amb.nt to add an
wscript.echo to the top of your script to verify the script is not being
run. Multiposting the same issue in other groups is not going to solve
the problem, especially when you refuse to provide positive feedback to
debugging suggestions.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
R.Wieser
2015-01-16 09:19:09 UTC
Permalink
Andy,
Post by Andy K
I 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 K
The 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 K
Post by R.Wieser
Andy,
Post by Andy K
I 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 K
I 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 K
OPTION 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 K
Sub 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 K
Function 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 K
Function 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 K
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
Andy
Andy K
2015-01-18 02:54:03 UTC
Permalink
Post by Andy K
I would like to run a batch file after a script file runs.
Can I do that ?
Thanks.
I decided to manually run my image backup program.

Todd's "negative waves" was a factor in my decision. :-)

He enjoys looking for things to complain about.

Andy
Todd Vargo
2015-01-18 06:19:09 UTC
Permalink
Post by Andy K
Post by Andy K
I would like to run a batch file after a script file runs.
Can I do that ?
Thanks.
I decided to manually run my image backup program.
Todd's "negative waves" was a factor in my decision. :-)
He enjoys looking for things to complain about.
Only a fool lies to himself.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
R.Wieser
2015-01-18 10:51:53 UTC
Permalink
Andy,
Post by Andy K
I decided to manually run my image backup program.
Todd's "negative waves" was a factor in my decision. :-)
Damn! I thought that *I* was in the running for that trophy. Now I have
to find someone else and start all over again. :-\ :-p

And a funny note: Todd was the one who tried to protect you from my
supposedly negative handling of you.

Also, your mentioning of "to manually run my image backup program" leads me
to believe that you have tried to start the script(s) by some other program.
That opens up another can of worms, like permissions on the files/folders
and the script(s) only having them when they are executed under your account
(when you are logged in and start them), but not when started under the
account that timer-program(?) runs under.

And again, that is missing information that is *important* to what you try
to do. :-(
Post by Andy K
He enjoys looking for things to complain about.
And you are bitching about the help you get, while seemingly trying to do as
little as possible yourself. :-(

You've been given multiple hints to try stuff so you can find the cause of
the posted problems yourself, but I've not seen you respond to any of them.
It gives me the feeling you do not want our *help*, but instead expect us to
fully solve the problem and than hand it to you on a silver platter.

...Which is never going to happen as a) your questions lack all kinds of
relevant information, making it impossible for us to know what the problem
actually is b) we are (or at least I am) not here to create free-of-charge
custom-tailored solutions.

Can I at least get a second-place "negative waves" medal for the above ? :-D

Regards,
Rudy Wieser
Post by Andy K
Post by Andy K
I would like to run a batch file after a script file runs.
Can I do that ?
Thanks.
I decided to manually run my image backup program.
Todd's "negative waves" was a factor in my decision. :-)
He enjoys looking for things to complain about.
Andy
Todd Vargo
2015-01-18 17:03:09 UTC
Permalink
Post by R.Wieser
Andy,
Post by Andy K
I decided to manually run my image backup program.
Todd's "negative waves" was a factor in my decision. :-)
Damn! I thought that *I* was in the running for that trophy. Now I have
to find someone else and start all over again. :-\ :-p
And a funny note: Todd was the one who tried to protect you from my
supposedly negative handling of you.
Also, your mentioning of "to manually run my image backup program" leads me
to believe that you have tried to start the script(s) by some other program.
That opens up another can of worms, like permissions on the files/folders
and the script(s) only having them when they are executed under your account
(when you are logged in and start them), but not when started under the
account that timer-program(?) runs under.
And again, that is missing information that is *important* to what you try
to do. :-(
Post by Andy K
He enjoys looking for things to complain about.
And you are bitching about the help you get, while seemingly trying to do as
little as possible yourself. :-(
You've been given multiple hints to try stuff so you can find the cause of
the posted problems yourself, but I've not seen you respond to any of them.
It gives me the feeling you do not want our *help*, but instead expect us to
fully solve the problem and than hand it to you on a silver platter.
....Which is never going to happen as a) your questions lack all kinds of
relevant information, making it impossible for us to know what the problem
actually is b) we are (or at least I am) not here to create free-of-charge
custom-tailored solutions.
Can I at least get a second-place "negative waves" medal for the above ? :-D
RAH, RAH! You get my vote for runner-up. :-D
Differences aside, your observations/points are all right on the mark.

Oh wait, I think was I supposed to respond to one of my own posts with
this. Oh well. :)
Post by R.Wieser
Regards,
Rudy Wieser
Post by Andy K
Post by Andy K
I would like to run a batch file after a script file runs.
Can I do that ?
Thanks.
I decided to manually run my image backup program.
Todd's "negative waves" was a factor in my decision. :-)
He enjoys looking for things to complain about.
Andy
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
R.Wieser
2015-01-18 18:03:02 UTC
Permalink
Todd,
Post by Todd Vargo
RAH, RAH! You get my vote for runner-up. :-D
Thank you for the support, that almost makes sure I'll win it. :-)
Post by Todd Vargo
Differences aside, your observations/points are all right on the mark.
Differences aside, did you notice that my current observations are pretty
much the same as in the message which started our altercation ?
Post by Todd Vargo
Oh wait, I think was I supposed to respond to one of my own posts with
this. Oh well. :)
Well, your reply certainly made me lol. So I don't mind you tagged it on.
:-)

Regards,
Rudy Wieser
Post by Todd Vargo
Post by R.Wieser
Andy,
Post by Andy K
I decided to manually run my image backup program.
Todd's "negative waves" was a factor in my decision. :-)
Damn! I thought that *I* was in the running for that trophy. Now I have
to find someone else and start all over again. :-\ :-p
And a funny note: Todd was the one who tried to protect you from my
supposedly negative handling of you.
Also, your mentioning of "to manually run my image backup program" leads me
to believe that you have tried to start the script(s) by some other program.
That opens up another can of worms, like permissions on the
files/folders
Post by Todd Vargo
Post by R.Wieser
and the script(s) only having them when they are executed under your account
(when you are logged in and start them), but not when started under the
account that timer-program(?) runs under.
And again, that is missing information that is *important* to what you try
to do. :-(
Post by Andy K
He enjoys looking for things to complain about.
And you are bitching about the help you get, while seemingly trying to do as
little as possible yourself. :-(
You've been given multiple hints to try stuff so you can find the cause of
the posted problems yourself, but I've not seen you respond to any of them.
It gives me the feeling you do not want our *help*, but instead expect us to
fully solve the problem and than hand it to you on a silver platter.
....Which is never going to happen as a) your questions lack all kinds of
relevant information, making it impossible for us to know what the problem
actually is b) we are (or at least I am) not here to create
free-of-charge
Post by Todd Vargo
Post by R.Wieser
custom-tailored solutions.
Can I at least get a second-place "negative waves" medal for the above ? :-D
RAH, RAH! You get my vote for runner-up. :-D
Differences aside, your observations/points are all right on the mark.
Oh wait, I think was I supposed to respond to one of my own posts with
this. Oh well. :)
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Todd Vargo
2015-01-19 02:23:09 UTC
Permalink
Post by R.Wieser
Todd,
Post by Todd Vargo
RAH, RAH! You get my vote for runner-up. :-D
Thank you for the support, that almost makes sure I'll win it. :-)
Post by Todd Vargo
Differences aside, your observations/points are all right on the mark.
Differences aside, did you notice that my current observations are pretty
much the same as in the message which started our altercation ?
Yes, but didn't want to call attention to it. :-)
Post by R.Wieser
Post by Todd Vargo
Oh wait, I think was I supposed to respond to one of my own posts with
this. Oh well. :)
Well, your reply certainly made me lol. So I don't mind you tagged it on.
:-)
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
R.Wieser
2015-01-19 07:54:49 UTC
Permalink
Todd,
Post by Todd Vargo
Yes, but didn't want to call attention to it. :-)
Ok. Thanks.

Regards,
Rudy Wieser
Post by Todd Vargo
Post by R.Wieser
Todd,
Post by Todd Vargo
RAH, RAH! You get my vote for runner-up. :-D
Thank you for the support, that almost makes sure I'll win it. :-)
Post by Todd Vargo
Differences aside, your observations/points are all right on the mark.
Differences aside, did you notice that my current observations are pretty
much the same as in the message which started our altercation ?
Yes, but didn't want to call attention to it. :-)
Post by R.Wieser
Post by Todd Vargo
Oh wait, I think was I supposed to respond to one of my own posts with
this. Oh well. :)
Well, your reply certainly made me lol. So I don't mind you tagged it on.
:-)
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Loading...