WSH in Other Languages
(Page 1 of 5 )
Much of the appeal of WSH lies in its simplicity. However, much of its power lies in its flexibility. Most often you will see WSH scripts written in VBScript, but in reality the Windows Script Host supports almost any COM-enabled scripting language.
Today we’re going to take a look at using WSH in other languages. WSH has built-in support for VBScript and JScript. These languages can be used out-of-box. In order to use other languages you must install a WSH-compatible engine for the language. This is also sometimes called an interpreter.
Many scripting languages have WSH-compatible engines available. When executing a script, the Windows Script Host determines which engine to use based on the script’s file extension. If the script uses a registered file extension, WSH is often able to determine this automatically.
Be aware that common file extensions may be associated with the original language runtime and not with the Windows Script Host. If not, you can specify what engine to use on the command line.
cscript /engine:PerlScript myscript.pl
Executing a script with a .pl file extension will execute it in the PerlScript runtime environment. The command line above will instead execute it within the WSH environment.
You might consider creating a file association for specific file extensions to be used with WSH. For example, you might use .pls for PerlScript files that you intend to run in WSH. This will avoid possible confusion and allow you to run your scripts without the additional command-line parameter.
This article is by no means comprehensive. I’m going to profile some of the more common languages that readers may want to use and provide a basic introduction that should get you up and running in the WSH environment. It would be impossible to teach every one of these languages within this article. Instead, I’m going to assume that readers have some exposure to the language and demonstrate how to use the WSH-compatible components.
Next: VBScript >>
More Windows Scripting Articles
More By Nilpo