Check Which VBScript Interpreter You Are Executing Your Script With

VBScript is a great language for management of Windows servers and desktops. The fact that Windows has built in interpreters for it makes it a really handy language for everything from gathering data to managing users to installing applications.

One cool feature about VBScript is that Windows has 2 built in interpreters. One is called wscript.exe and it has a couple handy features. It allows you to create pop-ups to display messages and request user input. This is great for running scripts that you expect people to interact with. The bad part about this though is that if your script is running and displays a message with something like the “wscript.echo” statement, the script will pause until someone is there to click the message away.

There is another built in interpreter for VBScript called “cscript.exe”. This one is great for command line based scripts that aren’t designed to run with user input. The confusing part about this interpreter is that the same “wscript.echo” statement simply displays a message at the command line. No user input required and the script continues to process normally, no pausing of the script.

Well because of this difference in behavior it sometimes becomes desirable to know which interpreter you are executing your scripts with. If you are running under “wscript.exe” you might not want to output informational messages or you may want to check beforehand if you even want to execute your script at all.

Well to check which interpreter you are running you can use this little function I whipped up called “CheckInterpreter”. If you are running under “wscript.exe” it returns “False” and if you are running under “cscript.exe” it returns “True”.

Function CheckInterpreter
  'This script is provided under the Creative Commons license located
  'at . It may not
  'be used for commercial purposes with out the expressed written consent
  'Checks to see if we should display error messages.
  'If running under cscript echoing errors to shell is ok.
  'If running under wscript echoing is NOT ok because
  'echoing errors will pause execution of the script.

  sScriptHost = LCase(Wscript.FullName)

  If Right(sScriptHost, 11) = "wscript.exe" Then
    CheckInterpreter = False
    CheckInterpreter = True
  End If
End Function


Leave a Comment