Converting the Windows Script Host Quit Method
Definition: Forces script execution to stop at any time.
This was a tough one for the Scripting Guys; needless to say, we don’t even know the meaning of the word “Quit.” (Needless to say, we don’t even know the meaning of a lot of words. But that’s another story.) As it turns out, though, the WSH method Quit provides a way to exit a script. Need to exit a script? Then just call the Quit method:
But wait, that’s not all. In addition to terminating a script, the Quit method enables you to specify an exit code when terminating that script. For example, this line of code terminates a script with an exit code of 32:
Why would you even want to specify an exit code when terminating a script? Well, for one thing, that enables you to easily determine why a script terminated, something you can do using this simple command-line command:
If you specify different exit codes for different situations (0 indicates that the script successfully completed its task; 1 indicates that a file could not be found; 2 indicates that the drive was not ready; etc.) you’ll never be left guessing why your script quit, or whether or not it succeeded.
Windows PowerShell provides the same capability via the Exit command. Need to terminate a script? Okey-doke:
Need to specify an exit code when terminating that script? That’s fine, too; just specify an exit code when terminating the script:
You can use the $LastExitCode variable to report back this exit code: