I write numerous little scripts that are shared and used among my coworkers, many of which are quick and easy VB scripts, many of which are run from cscript (rather than wscript). The end result? Well, often someone will see one of these script files and double-click it, which doesn’t work out to well for them and they usually get some sort of nasty error message since it’s not meant to be run in the wscript GUI mode.
“Yeah, nice script Matt. It’s full of bugs and won’t even run.” Um yeah. If you run it from the command line, the results would be much different, I assure you. So, how to tell Joe Blow that he should be running the script from the command line rather than happily double-clicking it? Use WScript.Fullname to determine the host and act from there.
My solution is pretty close to this function, and I’ll call this function pretty near the beginning of the script.
Function CScriptCheck If "cscript.exe" <> LCase(Right(WScript.Fullname, 11)) Then MsgBox "Run from a command prompt, fool!" WScript.Quit 1 End If End Function