Copyright: Windows Scripting Host Administrator's Guide © Microsoft Corporation 1998
Citation: Windows Scripting Host Administrator's Guide © Microsoft Corporation 1998


 Windows Scripting Host Administrator’s Guide Topics

Introduction

About Windows Scripting Host

Using Windows Scripting Host

Running Scripts Using Wscript.Exe

Running Scripts Using Cscript.Exe

Using the Wscript.Exe Properties Page

About .WSH Files

Running .WSH Files

About the Windows Scripting Host Sample Scripts

Links to More Information


Introduction
Windows Scripting Host Administrator’s Guide Topics

Introduction

This document is a guide for system administrators and others using the Microsoft Windows Scripting Host for running Visual Basic and JavaScript applications on server or client installations. It describes the procedures for running scripts using Wscript.Exe and Cscript.Exe, explains the use of .WSH files to customize the way your scripts run, and introduces the Windows Scripting Host sample scripts installed with the typical Windows 98 installation.

This document is not a programmer’s guide to the Windows Scripting Host object model, nor is it a tutorial on Visual Basic or JavaScript scripting.

For more information on these subjects, see Links to More Information.


About Windows Scripting Host
 Windows Scripting Host Administrator’s Guide Topics

About Windows Scripting Host

The Microsoft Windows Scripting Host is a language-independent scripting host for ActiveX scripting engines on 32-bit Windows platforms. With Windows Scripting Host, scripts can be run directly from the Windows 98 desktop, either by clicking on them in Windows Explorer or from a command line, eliminating the need to embed such scripts in HTML documents. Windows Scripting Host is ideal for running non-interactive scripts that perform logon and administrative tasks and machine automation. In addition to Windows 98, Windows Scripting Host is being integrated into Windows NT Workstation version 5.0, and Windows NT Server version 5.0.

Currently, Windows Scripting Host contains scripting engines for both Microsoft Visual Basic Scripting Edition (VBScript) and Microsoft Jscript. Scripting engines for other languages, such as Perl, TCL, REXX, and Python, have either been provided or are being provided by other software companies. See the Windows Scripting Host Website at:

HTTP://www.microsoft.com/management

for more information.

See also

Using Windows Scripting Host

About .WSH Files

About the Windows Scripting Host Sample Scripts

Links to More Information


Using Windows Scripting Host
Windows Scripting Host Administrator’s Guide Topics

Using Windows Scripting Host

Windows Scripting Host exists in two versions: a Windows-based host (Wscript.Exe)  and a command line-based host (Cscript.Exe).  You can use either host to run a script file, although when a file extension is registered with one host, subsequent files will run on that host until the file type registration is changed.

For information on running scripts with Windows Scripting host, see:

Running Scripts Using Wscript.Exe

Running Scripts Using Cscript.Exe

The Wscript.Exe Properties page allows you to set global scripting options for all scripts that are executed on the local machine. You can also set individual script settings on a per script basis by means of .WSH files, allowing you individual control over the execution of a given script.

For more information on setting options, see:

Using the Wscript.Exe Properties Page

About .WSH Files

Using .WSH Files

For links to information on the Windows Scripting Host Object Model, the Windows Scripting Host Website, and other information, see:

Links to More Information


Running Scripts from the Command Line
Windows Scripting Host Administrator’s Guide Topics

Running Scripts from the Command Line

Open command prompt now.

Prepare a script file with NOTEPAD.EXE or other text file editor. To execute the script, run CSCRIPT.EXE with the following syntax:.

cscript scriptfile [host options] [script options]

Where:

[scriptfile]

is the filename of the script file, complete with extension and any necessary path information, e.g.: d:\admin\vbscriptchart.vbs.

[host options]

are switches that enable or disable various Windows Scripting Host features. Host options are always preceded by two slashes (//)

[script options]

are parameters that are specified within the script and are passed to the script during execution. Script parameters are always preceded by a single slash (/).

Each parameter is optional; however, you cannot specify script options without specifying a script name. Typing cscript with no parameters displays the CSCRIPT.EXE syntax and the following valid host parameters:

Cscript Host Options

//I

Interactive Mode: allows display of user prompts and script errors (this is the default, and the opposite of //B).

//B

Batch Mode: suppresses command-line display of user prompts and script errors.

//T:nn

Enables time-out: the maximum number of seconds the script can run.

//logo

Displays a banner (default; opposite of //nologo).

//nologo

Prevents display of an execution banner at run-time.

//H:Cscript or

//H:Wscript

Registers Cscript.Exe or Wscript.Exe as the default application for running scripts. If neither is specified, Wscript.Exe is assumed as the default.

//S

Saves the current command-line options for this user.

//?

Shows command usage.


Command Line Example
Windows Scripting Host Administrator’s Guide Topics

Command Line Example

Several sample Windows Scripting Host scripts are provided with the Windows 98 Resource Kit. Upon installation of the Resource Kit, these sample scripts reside in the \Win98RK\WSH directory. For more information about these scripts, see About the Windows Scripting Host Sample Scripts.

Suppose, for purposes of this example, that you have copied the Chart.vbs sample script to the following folder on your computer:

C:\sample scripts\chart.vbs

To run this script with an execution logo, type this on the command line:

cscript //logo C: ‘\sample scripts\chart.vbs

See Also

Using Windows Scripting Host

About .WSH Files

About the Windows Scripting Host Sample Scripts

Links to More Information


Running Scripts using Wscript.Exe
 Windows Scripting Host Administrator’s Guide Topics

Running Scripts using Wscript.Exe

Using Wscript.Exe, you can run scripts under Windows 98 in three ways:

Double-clicking script files or icons. These can be files or icons listed in My Computer, Windows Explorer, the Find window, the Start menu, or the Desktop.

Entering a script name at the Run command on the Start Menu. Press the Start button, select Run, and enter the full name of the script you want to run, including file extension and any necessary path information.

Entering Wscript.Exe followed by a script name on the Run command line. Press the Start button, select Run, and enter Wscript, followed by the full name and path of the script you want to run.

Note  If you double-click a script file whose extension has not yet been associated with Wscript.exe, an Open With dialog box appears, asking which program you would like to use. To register Wscript.Exe as the default application for this file extension, click Wscript.Exe , and then check the Always use this program to open this file checkbox.

For information on setting the Wscript.Exe Properties options, See Using the Wscript.Exe Properties Page.


Using the Wscript.Exe Properties Page
 Windows Scripting Host Administrator’s Guide Topics

Using the Wscript.Exe Properties Page

The Wscript.Exe Properties page allows you to set global scripting options for all scripts that are executed on the local machine.

To access the Wscript Properties page, click Start, point to Run, and then type wscript.exe.

The following properties can be set on the Properties page:

Stop script after nn seconds

Specifies a maximum number of seconds that a script may run (default=no limit). Cscript.Exe equivalent=//T:nn.

Display logo when scripts execute in a command console

Displays an execution banner at execution time (default). Cscript equivalent: //logo  or //nologo.

You can also set options for individual scripts using a .WSH file. See About .WSH files.

See also:

Windows Scripting Host topics

Using Windows Scripting Host

About the Windows Scripting Host Sample Scripts

Links to More Information


About .WSH Files
 Windows Scripting Host Administrator’s Guide Topics

About .WSH Files

You can record specific settings for each individual script you run by creating a control file for that script with a .wsh file extension. A .wsh file is a text file that uses a format similar to that of .ini files.  Administrators in particular will find .wsh files useful. By creating multiple different .WSH files for a script, an administrator can tailor the way the script runs in given circumstances.

A sample .WSH file might contain the following text:

[ScriptFile]

Path=C:\WINDOWS\Samples\WSH\showprop.vbs

[Options]

Timeout=0

DisplayLogo=1

BatchMode=0

The path setting in the [ScriptFile] section identifies the script file that this .wsh file is associated with. The keys in the [Options] section correspond to settings in the Script tab within the Properties dialog box.

See also:

Creating .WSH Files

Running Scripts with .WSH Files


Creating .WSH Files
 Windows Scripting Host Administrator’s Guide Topics

Creating .WSH Files

A .WSH file is created automatically when you set the properties for a supported script file.

To create a .WSH file for a script

1	Right-click the script file in Windows Explorer.

2	On the context menu that appears, select Properties.

3	On the Properties page, choose the settings you want to take effect when the script is run.

4	Click OK or Apply.

A new .WSH file is automatically created, with the same name as the script file.

See also:

Windows Scripting Host topics

Running Scripts with .WSH Files

About .WSH Files


Running Scripts with .WSH Files
 Windows Scripting Host Administrator’s Guide Topics

Running Scripts with .WSH Files

To run a script with a .WSH file

Double-click the .WSH file in Windows Explorer to run the .wsh file and its associated script.

-- Or --

Pass the name of the .WSH file as a script argument to Cscript.Exe or Wscript.Exe on the command line. For example:

cscript Myscript.wsh

See also:

Creating .WSH Files

About .WSH Files


About the WSH Sample Scripts
 Windows Scripting Host Administrator’s Guide Topics

About the Windows Scripting Host Sample Scripts

Windows 98 ships with several sample scripts designed to demonstrate Windows Scripting Host objects and methods. These sample scripts are installed in the \\Windows\Samples\WSH directory upon Windows 98 installation. To run a sample script, double-click the filename in Windows Explorer. To open a sample script and view its contents, go to the \\Windows\Samples\WSH directory of your hard drive and type notepad scriptname.extension on a command line.

The Windows Scripting Host sample scripts are:

CHART    VBS

This sample demonstrates how to access Microsoft Excel using the Windows Scripting Host.

EXCEL    VBS

This sample demonstrates methods for running applications. It creates an Excel spreadsheet and propagates it with Windows Scripting Host properties information.

NETWORK  VBS

This sample demonstrates how to use the WSHNetwork object. It reads network properties (username and computername), connects, disconnects, and enumerates network drives.

REGISTRY VBS

This sample demonstrates how to write/delete entries in the registry.

SHORTCUT VBS

This sample demonstrates how to use the WSHShell object to create a shortcut on the desktop.

SHOWPROP VBS

This sample demonstrates methods for getting and displaying Windows Scripting Host application and version information during script execution.

CHART    JS

EXCEL    JS

NETWORK  JS

REGISTRY JS

SHORTCUT JS

Jscript versions of the VBscript samples above.

SHOWVAR  VBS

This sample demonstrates methods for gathering system information. It lists all environment variables defined on this machine.

Windows Scripting Host topics

Using Windows Scripting Host

Windows Scripting Host example


Extensions to the WSH Object
 Windows Scripting Host Administrator’s Guide Topics

Extensions to the Windows Scripting Host Object Model

The Windows Scripting Host object exposes methods for shell and  Registry access, networking functions, and OLE automation. See the Windows Scripting Host Sample Scripts for examples of these methods in use.

Currently, the Windows Scripting Host object library does not support methods for file or folder manipulation on local machines. However, these operations can still be performed with Windows Scripting Host using the Scripting.File.System.Object methods exposed in SCRRUN.DLL, which is installed with Windows 98.

For more information and complete Object reference, go to [image] HTTP://www.microsoft.com/scripting on the World Wide Web, and search on "Scripting.FileSystemObject".

See Also

About the Windows Scripting Host Sample Scripts

Links to More Information


Links to More Information
 Windows Scripting Host Administrator’s Guide Topics

Links to More Information about Windows Scripting Host

For more information on Windows Scripting Host, including a complete programmer’s reference to the Windows Scripting Host object model as well as links to information about scripting engines being written to support third-party scripting languages, visit the Windows Scripting Host Web site at [image] HTTP://www.microsoft.com/management.

For information on File and Folder Object extensions to the Windows Scripting Host object library, see Extensions to the Windows Scripting Host Object.