46

I Have an old vbs script file being kicked off by an AutoSys job. Can I, and how do I, return an int return value to indicate success or failure?

Rob
  • 45,296
  • 24
  • 122
  • 150
Philip.ie
  • 1,506
  • 1
  • 17
  • 19

2 Answers2

65

Try:

WScript.Quit n

Where n is the ERRORLEVEL you want to return

Rob
  • 45,296
  • 24
  • 122
  • 150
  • using `Quit` is undesired in cases where your script is activate withing another script. it will also stop the "main" script execution – idanshmu Oct 27 '16 at 07:26
37

I found the answer :0)

 DIM returnValue
 returnValue = 99
 WScript.Quit(returnValue)

This seems to work well.

Philip.ie
  • 1,506
  • 1
  • 17
  • 19
  • 2
    This is basically the same as what at @Rob posted, but may be better if you follow a convention of having a single exit point to the script (as the very last line), and then set `returnValue` else where in the flow of your code. Note that if you use that approach, you'll probably want to include on `On Error Resume Next` at the start of your script, to avoid implicit fatal errors. – BuvinJ Sep 18 '20 at 12:55