I suspect I know the answer, but I want to confirm. If I have a controlling
script (script A) which calls another script (Script B) using Wscript.Exec
command, will the ExitCode always be 0 when I read ExitCode attribute on the
returned WshScriptExec object?
For example:
'Script A
Set objShell = CreateObject("WScript.Shell")
Err.Clear
Set objExec = objShell.Exec("%comspec% /c cscript //nologo c:\temp\test2.vbs")
Do While objExec.Status = 0
Wscript.Sleep(100)
Loop
Wscript.WriteLine("Error Code: (" & objExec.ExitCode & ") ")
'Script B
Wscript.Echo " Starting Test - Test2.vbs"
Wscript.Sleep(4000)
Wscript.Echo " Ending Test - Test2.vbs"
Err.Raise vbObjectError+3,"","Testing Failure Code 3"
Wscript.Quit(3)
I would expect that the last line in Script A would print "Error Code: (3)",
but rather I get a 0.