An Introduction to Windows Scripting
JOHN E. JOHNSTON An Introduction to Windows Scripting
n the past, BAT files provided Windows users a way to run a series of commands. Today, with the I release of Microsoft's Windows Scripting Host, there are many different platforms on which we can run scripts, including Internet Explorer, Internet Information Server and the Windows operating system.
of us were first introduced to microcomputers via HTML pages, please keep in mind that you can also MANYback in the days when DOS was the major develop scripts that run under the Windows operating system. operating system for business and personal computers. If we This type of script performs like a BAT file, but is much more needed to automate the running of a series of commands, we versatile. With operating system scripts, you can automate made BAT files to accomplish this. Then along came many of the routine tasks performed in your organization, Windows Version 3, and still, if we needed to run a series of such as editing and copying files between different computers, commands, we relied on BAT files. managing file server backup processes, Even with Windows 9x and Windows and automating the scheduling of rou- NT, the lowly BAT file remains as the The Windows interface tine application tasks. only native scripting tool available to allows you to run script us. At the same time, our mainframe WINDOWS SCRIPTING colleagues have been using clists and files directly from COMPONENTS REXX programs to develop rather sophisticated scripting applications Windows. For example, Windows Scripting is comprised of and our UNIX counterparts have the following two major components: been using the very versatile shell to launch a script under scripts for their scripting applica- Windows Script Engines tions. Today, with the release of the this interface, you can Windows Script Hosts Windows Scripting Host, Microsoft has addressed this deficiency in the simply open the Windows Windows Script Engines are com- Windows operating environment. Explorer program, browse ponents that allow a certain scripting This article examines the new language to be utilized in the develop- scripting capabilities available and to the directory containing ment of Windows scripts. Microsoft explores the different platforms on provides two scripting engines that which we can run scripts, including the script file and double you can use to develop your own Internet Explorer, Internet Information Windows scripts: the Visual Basic Server and the Windows operating click on the file. Scripting Edition (VBScript) and the system. Several samples will also be Java Script (Jscript) scripting engine. presented that will show you how to These script engines interpret the run scripts from HTML pages. Additionally, several resources, script commands and work with the Windows Script Host to including web sites where you can learn more about Windows execute these commands. scripting, are presented at the end of this article. These sites The Windows Script Hosts are scripting components that contain valuable reference material and many sample scripts sit between the Windows operating system and the Windows that you can use to help you learn this new tool. Script Engines. Currently, the following three Windows While this article only presents examples of running scripts Script Hosts are available:
TECHNICAL SUPPORT • MARCH 2000 ©2000 Technical Enterprises, Inc. Reproduction of this document without permission is prohibited. Windows Script Host CSCRIPT.EXE program. For example, you on the file. The Windows interface also Internet Explorer can invoke a VBScript file using the allows you to invoke scripts using the Internet Information Server (IIS) following command from the Windows Windows RUN command. To execute a Command prompt: script in this manner, click on Start > Run, Windows Script Host and then enter the path and file name of the Windows Script Host provides two inter- cscript c:\vbscripts\automate\backitup.vbs script to be executed. The Windows interface faces for launching script files. One of the provides one last method for invoking interfaces is used to launch script files from The Windows interface allows you to run scripts by using the WSCRIPT.EXE program. the Windows command prompt, while the script files directly from Windows. For This program allows you to specify optional other interface allows you to launch script example, to launch a script under this inter- parameters to the Script Host. To execute a files under Windows. face, you can simply open the Windows script using WSCRIPT.EXE, click on Start The Windows Script Host Command Explorer program, browse to the directory > Run, then enter the following: prompt interface is provided in the containing the script file and double click Wscript.exe script.name [options] [arguments]
FIGURE 1: THE OPTIONS AVAILABLE UNDER THE WSCRIPT.EXE INTERFACE Figure 1 shows the options available under the WSCRIPT.EXE interface.
Internet Explorer You can use the Windows Internet Explorer to launch scripts from within HTML pages. This is a very useful tool when implementing web-based applications. Note that Windows 95 users must either have OSR2 installed or be running Microsoft Internet Explorer 4.0 or later.
Internet Information Server (IIS) One of the most important scripting hosts is the IIS scripting host. You can invoke scripts from within Active Server Pages via the Internet Information Server. This allows you to implement server-side scripting for FIGURE 2: SAMPLE VBSCRIPT EXECUTION FROM WITHIN AN HTML FILE your web applications.
OBTAINING WINDOWS SCRIPTING COMPONENTS
The latest Windows scripting components can be downloaded from www.microsoft.com/ msdownload/ vbscript/scripting.asp. From this page, download the file named ste51en.exe. This file contains the following components: