Overview Of The New Windows Scripting Host 5.6 - Heeeeeeeere's Your Host.
(Page 3 of 7 )
So now that you're well versed in what a script is (if you weren't to begin with), you probably want to know what a script host is. In short, a script host is a program that provides an environment in which users can execute scripts. If you're reading this, there's a 99.99% chance that you've used a script host before. For you *nix folks, shell programs such as C shell, Bash, and Korn shell are script hosts that use an object model that enable you to manipulate a file system. The DOS prompt can be thought of as a scripting environment because it can run scripts written in the "batch file" language. Heck, if you're reading this while using a browser that can execute scripts that use the Dynamic HTML object model, then you're using a script host right now!
That being said, the Windows Script Host (WSH) is what allows you to run scripts in the Windows platform by creating an environment for hosting scripts. It's a general purpose scripting environment that can run scripts in a variety of languages that use a variety of object models to perform specific tasks. That's because it imposes no restrictions on either the language used to write the script or the object model used by the scripts. In fact, it's a bit like the whole .NET thing, exercising the philosophy of many languages, one platform. Here's an overview of how it works:
When you run a script that you or someone else has written, the WSH will call the correct script engine in order to perform the given task(s), depending on what kind of script you wrote (whether it be JScript, VBScript, or with special preparation Perl, Python, REXX, among others). Now, it doesn't matter whether you double click on the script, run it from the command line, call it from another script, or it comes to you over a network; The WSH still comes up and runs it, provided it meets certain criteria.
If you're like me, you're probably thinking, "Hey, wait a minute? What about security? What do you mean it just 'runs it'?" Well, with the latest version of WSH, there's an improved security model which addresses some of those concerns. This is why you should make sure that you're running the latest release of WSH. You can go to the Microsoft website and
download the latest version (5.6, as of this writing). If you're running Windows XP or 2003, don't worry - you're already up to date. For more information on the security improvements, loving in the wrong kind of way, and ugly babies, check out the
MSDN scripting website. Note that all the information in this tutorial pertains to this latest version.
Ok, so you're running the latest version of WSH. Now you're ready to run scripts written in VBScript, JScript, or your favorite scripting language. All you have to do is double-click on any file that has the .js, .vbs or .wsf extension and that file will be executed within the WSH environment. Of course, you can also open up a DOS prompt to the right directory and run it from there. I don't recommend doing this with every .vbs, .js, or even .wsf file you can find, however. Not unless you want a virus infestation on your system bad enough to annoy
Robin Miller. You'll want to make sure that your anti-virus definitions are up to date and that you scan every file that you didn't write. After testing your scripts thoroughly, you can even use the Windows Task Scheduler to schedule when to run them. For example, you can have Windows run WSH and the script automatically whenever Windows starts up or when you want to make sure you don't miss Futurama re-runs.
Next: New Contestants, Come On Down! >>
More Windows Scripting Articles
More By Norbert Cartagena