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.

RE: Retrieving Exit Code from Script executing using Exec command by CharlesDenny

CharlesDenny
Tue Apr 05 15:03:03 CDT 2005

Nevermind, after looking at it again, I see the problem in script B test code.

Either I need to remove the Err.Raise command or put an "On Error Resume
Next" into the script. ;) By raising the error there, I end up killing the
script and it never makes it to the Quit command....

"Charles Denny" wrote:

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