Windows Script Host: A Universal Scripting Host for Scripting Languages

waisttherapeuticSoftware and s/w Development

Nov 4, 2013 (3 years and 11 months ago)

79 views


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 issu
es 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 aft
er 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 tra
demarks 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



INTRODUCTION

................................
................................
..........

1

BENEFITS OF THE WIND
OWS SCRIPT HOST

.............................

2

Implementing More Powerful Scripts

2

Windows Scripting Options

2

WSH INSTA
LLATION

................................
................................
...

3

Windows 95 Operating System

3

RUNNING SCRIPTS USIN
G THE COMMAND
-
BASED SCRIPTING
HOST
................................
................................
............................

4

WSH Command Example

5

To run Chart.vbs

5

RUNNING SCRIPTS USIN
G WINDOWS
-
BASED SCRIPT HOST
...

6

WSH ARCHITECTUAL OVE
RVIEW

................................
..............

7

FOR MORE INFORMATION

................................
..........................

8


CONTENTS



Microsoft Windows

2000 Server White Paper

1

The Windows Scrip
t 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 so
ftware 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.


INTRODUCTION


Microsoft Windows

2000 Server White Paper

2

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
syste
m 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 JSc
ript, 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 scrip
ting 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 c
onsole, 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 scriptin
g needs, such as logon scripting, administrative scripting,
and so on.


BENEFITS

OF THE
WINDOWS SCRIPT HOST



Microsoft Windows

2000 Server White Paper

3

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
Exp
lorer 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 W
SH 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 Expl
orer Web page
.

Download WSH Setup from the
Microsoft download site.

WSH INSTALLATION


Microsoft Windows

2000 Server White Paper

4

Cscript.exe uses the following syntax:

cscript [host op
tions…] [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 t
o 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 t
he 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 usin
g
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 p
revent 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).


RUNNING SCRIPTS
USING THE COMMAND
-
BASED SCRIPTING
HOST



Microsoft Windows

2000 Server White Paper

5

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



Microsoft Windows

2000 Server White Paper

6

There are three ways to run scripts in the Windows operating sy
stem, 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 Pr
operties
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 scri
pt 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


RUNNING SCRIPTS
USING WINDOWS
-
BASED
SCRIPT HOST



Microsoft Windows

2000 Server White Paper

7

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 scri
pt engine by the
IActiveScriptParse::ParseScriptText

method
provided by the script engine.


Java

Script

(3) Map file to appropriate scripting engine

host

(1) Run script file

Windows Shell

Windows Script Host

Registry

(

2) Map file

association to

Windows scripting

(4) Run appro
priate scripting engine via

IActiveScriptParse::ParseScriptText

(5) Execute Script. Communicate with

scripting host as necessary

Visual

Basic

Script

Engine

PERL,

REXX,

TCL,

Python,

and so

forth


The scripting engine does not use the SCRIPT tag (used in HTML); instead, it relies
on the extension of the file. Therefore, the script w
riter 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.

WSH ARCHITECTUAL
OVERVIEW


Microsoft Windows

2000 Server White Paper

8

Fo
r 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 script
ing technology, visit the
Microsoft
Developer Network.

FOR MORE INFORMATION



Microsoft Windows

2000 Server White Paper

9