Windows Scripting Host: Universal Scripting Host in scripting language (full text)

Source: Internet
Author: User

Summary

Windows Scripting host (wsh) is a language-independent Scripting host for 32-bit Windows platforms. Windows Scripting host will be integrated into the update program and new version of Microsoft Windows.

Introduction

Windows Scripting host (wsh) is a language-independent Scripting host for 32-bit Microsoft Windows operating system platforms. Microsoft also provides wsh for Visual BASIC script and Java Script Engine. Microsoft expects that other software companies will provide ActiveX script engines to other languages (such as Perl, TCL, Rexx, and Python.

Wsh can run (wscript.exe) on a Windows-based host or on a command line interpreter (cscript.exe ).

This article describes:

  • Wsh usage.
  • How to install wsh.
  • How to Use wsh.

Windows Scripting host has been integrated into Windows 98, Internet Information Server 4.0, Windows 2000 Server, and Windows 2000 Professional. It can also be used in Windows 95 operating systems.

Advantages of Windows Scripting Host

Windows Scripting host (wsh) provides 32-bit Windows platforms with easy-to-use, powerful, and flexible scripts.

In the past, the only authentic scripting language supported by windows was the MS-DOS command language. Although the MS-DOS is fast and small, it has limited functionality than visual basic script and Java Script. The ActiveX script architecture now allows users to use powerful scripting languages such as Visual BASIC script and Java Script, while also supporting MS-DOS command scripts.

The ActiveX script architecture allows you to write powerful scripts in languages such as VB script, Java Script, and Perl. Microsoft currently runs these scripting languages on Windows platforms and provides three hosts:

  • Microsoft Internet Explorer
  • Internet Information Server (IIS)
  • Windows Scripting host (wsh)

Internet Explorer allows scripts to run from the HTML page on the client's computer.

Internet Information Server now supports Active Server Page, which enables scripts to run on Web servers. In other words, it enables server scripts on the Internet or intranet.

The Windows Scripting Host enables the script to be executed directly on the Windows desktop or command console, without the need to embed the script into the HTML document. The script can be run directly from the desktop (by clicking the script file) or the command console. Wsh provides a Script Host with less memory consumption and is suitable for non-interactive scripts, such as logon scripts and management scripts.

Wsh Installation

To use Windows Scripting host, you must install Microsoft Internet Explorer 3.0 or later. Wsh depends on the Visual BASIC script and Java Script Engine provided with Internet Explorer 3.0 or later. Wsh is installed as part of Windows 98, Windows 2000, and Internet Information Server 4.0. To install it in Windows 95, a separate installation program is required.

To install wsh on a Windows 95-based system, you must install wsh if Microsoft Internet Explorer 3.0 or later is not installed. If you do not have Internet Explorer 3.0 or later, see the Microsoft IE web page at http://www.microsoft.com/ie/ie.htm.

Download the wsh installer from the Microsoft download site at http://www.microsoft.com/msdownload/vbscript/scripting.asp.

Run scripts on a command-Based Script Host

Cscript.exe uses the following syntax:

Cscript [host optionsu] [Script Name] [script options]

  • Host Parameters(Host parameters) enable or disable various wsh options. There are two diagonal lines (//) before the host parameter (//).
  • Script Name(Script Name) is the name of the script file, for example, chart. vbs.
  • Script Parameters(Script parameter) is passed to the script. There is a slash (/) in front of the script parameter (/).

Each parameter is optional. However, you cannot specify a script parameter instead of a script. If you do not specify the parameter, cscript.exe displays the cscript.exe syntax and valid host parameters.

Cscript.exe supports the following host parameters:

Parameters Description
// R Search for the registered script engine to register the script extension (. vbs,. JS,. TCL ).
RemarksWhen you use the // R transfer command, you do not need to provide the script file name.
// I Interactive Mode (default value, opposite to // B)
// B Batch processing mode. Prohibit any non-command line console UI requested by the script.
// T: NN

Timeout (in seconds ). Maximum time that a script can run. The default value is no limit (no limit ). This option is used to prevent the script from being executed for too long; it sets a timer. When the execution time exceeds the specified value, cscript uses the iactivescript: interruptthread method to interrupt the script engine and terminate the process.
RemarksThere is a call-back Hook. If the call times out, the ontimeout function is called for cleanup. Although infinite loops may occur, using this function has few advantages and disadvantages.

// Logo Display the execution banner flag during execution (default value-opposite to // nologo ).
// Nologo The execution banner flag is not displayed during execution.
// C Use cscript.exe as the default application for running scripts.
// S Save the current command line option for this user (each user.
// Display command usage (same as running without parameters ).

Some script examples will be installed when wsh is installed. The script example is stored in the % WINDIR %/wsamples folder (Where % Windir % is a Windows 95 or Windows 2000 folder ).

To run chart. vbs

  1. Go to Windows 2000 or Windows 95 command prompt.
  2. Run the following command:
    Cscript // logo % WINDIR %/wsamples/chart. vbs
    Cscript // nologo % WINDIR %/wsamples/chart. vbs

Run scripts on a Windows-based Script Host

In Windows, wsh can be used to run scripts in three ways. Yes:

  • Double-click files and icons in the my computer, resource manager, and search windows.
  • Run the "run" command on Windows.
  • Run wscript.exe.

When you use wscript.exe to run the script, you can select the "always use Windows Scripting host to open this file" check box and set properties on the "wsh properties" page.

When you run the script and select "always use Windows Scripting host to open the file option again", wscript.exe becomes the Default Application for running these files for a file with a proper extension name. For example, if you select this option when running chart. vbs, wscript.exe becomes the default application that runs all files with the extension. vbs. This check box also applies to cscript.exe/c Transfer commands.

Wsh attributesPage provides the following options:

Attribute Purpose Cscript. exe
Register common script extensions By searching common registration script engines, you can re-register common script extensions (. vbs,. JS,. TCL ). // R
Terminate the script in n seconds Specifies the maximum number of seconds for a script to run. (The default value is unlimited .) // T: NN
By default, scripts are run in the following column modes: interaction/batch processing Disable or enable all non-cli console UI requests for scripts. Interactive Mode allows non-cli console UI requests. Batch processing is not allowed. // I & // B

Wsh Architecture Overview

The Windows Scripting host is used as the controller of the ActiveX Script Engine and serves as Microsoft Internet Explorer. Because the Script Host is not a completely Internet browser, it requires less memory than Microsoft Internet Explorer; therefore, wsh is suitable for performing simple and fast tasks.

The Script Host reads the content of the specified script file according to the iactivescriptparse: parsescripttext method provided by the script engine and sends it to the registered script engine.

The script engine uses the file extension instead of the script tag (used in HTML. Therefore, the script writer does not need to be familiar with the exact progid of various script engines. This script host maintains a ing between the script extension and progid, and starts the corresponding engine in Windows Association mode.

Other information

For the latest information about Windows 2000 Server, see Microsoft technet or visit the Web site on Windows 2000 Server Forum (Go word: msets) on a http://www.microsoft.com/china/windows2000/ or Microsoft Network ).

For the latest information about Windows Script technology, visit Microsoft Developer Network at http://www.microsoft.com/china/msdn /.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.