Operating System Windows Script Host



Download 40.25 Kb.
Date31.07.2017
Size40.25 Kb.
#25715


Operating System

Windows Script Host:

A Universal Scripting Host for Scripting Languages

White Paper

Abstract

The Windows Script Host (WSH) is a language-independent scripting host for 32-bit Windows platforms. Windows Script Host will be integrated into updates and new releases of the Microsoft® Windows® operating system.



© 1999 Microsoft Corporation. All rights reserved.

The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.

This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT.

ActiveX, JScript, Visual Basic, Microsoft, Windows, and Windows NT are either trademarks or registered trademarks of Microsoft Corporation.

Other product or company names mentioned herein may be the trademarks of their respective owners.

Microsoft Corporation • One Microsoft Way • Redmond, WA 98052-6399 • USA

0499

Contents


White Paper 1

Introduction 1

BENEFITS of THE Windows Script host 1

Implementing More Powerful Scripts 1

Windows Scripting Options 1

WSH Installation 2

Windows 95 Operating System 2

Running Scripts Using the Command-based Scripting Host 2

WSH Command Example 4

Running Scripts Using Windows-based Script Host 4

WSH Architectual Overview 5

FOR more information 6





Introduction



The Windows Script Host (WSH) is a language-independent scripting host for 32-bit Microsoft® Windows® operating system platforms. Microsoft provides both Visual Basic® Scripting Edition (VBScript) and JScript® scripting engines with WSH. Microsoft anticipates that other software companies will provide ActiveX® scripting engines for other languages, such as Perl, TCL, REXX, and Python.

WSH can be run from either the Windows-based host (Wscript.exe) or the command shell–based host (Cscript.exe).

This paper describes:


  • The uses of WSH.

  • How to install WSH.

  • How to use WSH.

Windows Script Host is integrated into Windows 98, Internet Information Server version 4.0, Windows 2000 Server, and Windows 2000 Professional. It is also available for the Windows 95 operating system.

BENEFITS of THE Windows Script host



Windows Script Host (WSH) brings simple, powerful, and flexible scripting to the 32-bit Windows platform.

Implementing More Powerful Scripts


Previously, the only native scripting language supported by the Windows operating system was the MS-DOS® command language. Although it is fast and small,
MS-DOS has limited features, compared to VBScript and JScript. Today, ActiveX scripting architecture allows users to take advantage of powerful scripting languages such as VBScript and JScript, and MS-DOS command scripts are still supported.

Windows Scripting Options


ActiveX scripting architecture enables powerful scripting, using languages such as VBScript, JScript, and Perl. Microsoft currently provides three hosts for running these scripting languages across the Windows platform:

  • Microsoft Internet Explorer

  • Internet Information Server (IIS)

  • Windows Script Host (WSH)

Internet Explorer enables scripts to be executed on client computers from within HTML pages.

Internet Information Server now supports Active Server Pages, which enable scripts to be run on Web servers; in other words, it enables server-side scripting over the Internet or an intranet.

Windows Script Host enables scripts to be executed directly on the Windows desktop or command console, without the need to embed those scripts in an HTML document. Scripts can be run directly from the desktop by clicking on a script file, or from the command console. WSH provides a low-memory scripting host that is ideal for non-interactive scripting needs, such as logon scripting, administrative scripting, and so on.

WSH Installation



You must install Microsoft Internet Explorer version 3.0 or later to use Windows Script Host. WSH relies on the VBScript and JScript engines provided with Internet Explorer 3.0 or later. WSH is installed as part of the Windows 98 and Windows 2000 operating system family, and Internet Information Server 4.0. A separate setup program is provided for the Windows 95 operating system.

Windows 95 Operating System


To install WSH on a Windows 95–based system, install Microsoft Internet Explorer version 3.0 or later if you have not already done so. If you do not have Internet Explorer 3.0 or later, see the Microsoft Internet Explorer Web page.

Download WSH Setup from the Microsoft download site.


Running Scripts Using the Command-based Scripting Host



Cscript.exe uses the following syntax:

cscript [host options…] [script name] [script options]



  • Host parameters enable or disable various WSH options. Host parameters are always proceeded by two slashes (//).

  • The script name is the name for the script file, for example, CHART.VBS.

  • Script parameters are passed to the script. Script parameters are always preceded by one slash (/).

Each parameter is optional; however, you cannot specify script parameters without specifying a script. If you do not specify parameters, Cscript.exe displays the Cscript.exe syntax and the valid host parameters.

Cscript.exe supports the following host parameters:



Parameter

Description

//R

Reregister script extensions (.vbs, .js, .tcl) by searching for registered script engines.
NOTE You do not need to provide a script file name when using the //R switch.

//I

Interactive mode (Default—Opposite of //B)

//B

Batch mode. Suppress all non-command-line console UI requested from script.

//T:nn

Time-out, in seconds. Maximum time the script can run (Default = No limit).

This option is used to prevent excessive execution of scripts; it sets a timer. When execution time exceeds the specified value, Cscript interrupts the script engine, using the IActiveScript::InterruptThread method and terminates the process.

NOTE There is a callback hook. If the time-out is invoked, the OnTimeOut function is called to permit some cleanup. Although it is possible to create infinite loops, using this feature, it is more useful than harmful.


//logo

Display an execution banner at execution time (Default—Opposite of //NoLogo).

//nologo

Prevent display of execution banner at execution time.

//C

Make Cscript.exe the default application for running scripts.

//S

Save current command-line options for this user (per user).

//?

Show command usage (same as execution with no parameters).

WSH Command Example


Several sample scripts are installed when you install WSH. The sample scripts are in the %windir%\WSamples folder (where %windir% is your Windows 95 or Windows 2000 folder).

To run Chart.vbs


  1. Go to the Windows 2000 or Windows 95 command prompt.

  2. Run the following commands:

cscript //logo %windir%\wsamples\chart.vbs

cscript //nologo %windir%\wsamples\chart.vbs


Running Scripts Using Windows-based Script Host



There are three ways to run scripts in the Windows operating system, using WSH. You can:

  • Double-click files and icons in My Computer, Windows Explorer, and the Find window.

  • Use the Windows Run command.

  • Run Wscript.exe.

When you run scripts from Wscript.exe, you can select the Always Use the Windows Script Host to open this file checkbox and set properties on the WSH Properties page.

When you run a script and the Always Use the Windows Script Host to open this file checkbox is selected, Wscript.exe is registered as the default application to run files with the extension of the script you are running. For example, if you select the checkbox when you run Chart.vbs, Wscript.exe becomes the default application for all files with the .vbs extension. This checkbox functions identically to the Cscript.exe //C switch.

The WSH Properties page provides the following options:

Property

Use to…

CSCRIPT.EXE equivalent

Register common script extensions

Re-register the well known script extensions (.vbs, .js, .tcl, ) by searching for well known registered script engines.

//R

Stop script after n seconds

Specify a maximum number of seconds that a script may run. (The default is no limit.)

//T:nn

By default, run scripts in the following mode:
Interactive/Batch

Suppress or enable all non-command-line console UI requests from the script. Interactive allows non-command-line console UI requests. Batch does not.

//I & //B




The Windows Script Host serves as a controller of ActiveX scripting engines, just as Microsoft Internet Explorer does. Because the scripting host is not a full Internet browser, it has smaller memory demands than Microsoft Internet Explorer; therefore, WSH is appropriate for performing simple, quick tasks.

The scripting host reads and passes the specified script file contents to the registered script engine by the IActiveScriptParse::ParseScriptText method provided by the script engine.

The scripting engine does not use the SCRIPT tag (used in HTML); instead, it relies on the extension of the file. Therefore, the script writer does not have to be familiar with the exact ProgID of various script engines. The scripting host maintains a mapping of the script extensions to ProgIDs and uses the Windows association model to launch the appropriate engine.




For the latest information on Windows 2000 Server, visit the Microsoft Web site or the Windows 2000 Server Forum on the Microsoft Network (GO WORD: MSNTS).

For the latest information on Windows scripting technology, visit the Microsoft Developer Network.






Download 40.25 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page