Properly set exit code for process.

Supercedes #246.
Includes provisions for buggy behavior of WScript.Quit.