Let's say your script you are running is called "Canada.vbs" and let's say the script that will return the code "Mexico.vbs".
CANADA.VBS Code (This is what you will run.):
Dim ExitCode
Dim Return
Dim WshShell
Set WshShell=CreateObject ("WScript.Shell")
Dim Command
Command="Mexico.vbs"
Command=Chr(34) & Command & Chr (34)
ExitCode=WshShell.Run (Command, 1, True)
If ExitCode="1" Then
Return="Success"
ElseIf ExitCode="2" Then
Return="Failure"
Else
Return="Unknown"
End If
MsgBox Return
MEXICO.VBS Code (This is what Canada will run.):
Dim Success
Success=MsgBox ("Do you want to Succeed?",vbQuestion + vbYesNo,"Your Goals are good?")
success=success-7 'Vbyes=6 vbno=7. True=-1 False=0.
'The Above Code is only for demonstration purposes. You may set success in your own statement
If Success Then 'Successful
Success=1
ElseIf not Success Then 'Failure
Success=2
Else 'Unknown
Success=0
End If
WScript.Quit (Success)
Ok now in Canada you will need to declare a variable that will hold the exit code of Mexico. Let's name it
Dim ExitCode
We are also going to need a String Variable (Although you can double up the ExitCode variable as this but doing so could make debugging difficult with large files. so let's keep them seperate.)
Dim Return
and we are going to need an object that will run the Mexico.vbs. the object we need is the Wscript Shell
Dim WshShell
Set Wshshell=CreateObject ("WScript.Shell")
Now we need to Specify the Script to run. the script path being "Mexico.vbs"
Dim Command
Command="Mexico.vbs"
Now JUST IN CASE there are any spaces in the filepath (there isn't but let's be safe) we need to enclose the path in quotes. (Character code: 34)
Command=Chr(34) & Command & Chr (34)
Now we need to run the Mexico.vbs from the Canada.vbs and save the return to a variable
ExitCode=WshShell.Run (Command, 1, True) 'command is path, 1 is window state, true is wait for return.
Now we format the ExitCode into an UserFriendly string.
If ExitCode="1" Then
Return="Success"
ElseIf ExitCode="2" Then
Return="Failure"
Else
Return="Unknown"
End If
Now we will display the Result in a msgbox.
MsgBox Return
In Mexico.vbs you will be sending the success or failure through an exit code.
We will name the exitcode variable Success
Dim Success
THIS PART IS FOR DEMONSTRATION PURPOSES. You can exclude this portion and replace it with your auditing statements. Just set the Success to true if successful or False if Failure.
Success=MsgBox ("Do you want to Succeed?",vbQuestion + vbYesNo,"Your Goals are good?")
success=success-7 'Vbyes=6 vbno=7. True=-1 False=0.
'The Above Code is only for demonstration purposes. You may set success in your own statement
Now we will convert the bool Success into an Integer, 1=success,2=failure,0=unknown
If Success Then 'Successful
Success=1
ElseIf not Success Then 'Failure
Success=2
Else 'Unknown
Success=0
End If
And now we will terminate the Mexico.vbs Script with the exit code set in Success.
WScript.Quit (Success)