Windows Script Host
Encyclopedia
The Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

 Windows Script Host (WSH) is an automation technology for Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s that provides scripting capabilities comparable to batch file
Batch file
In DOS, OS/2, and Microsoft Windows, batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter....

s, but with a greater range of supported features. It was originally called Windows Scripting Host, but was renamed for the second release.

It is language-independent in the sense that it can make use of different Active Scripting
Active Scripting
Active Scripting is the technology used in Windows to implement component-based scripting support. It is based on COM and allows installation of additional scripting engines in the form of COM modules.-Uses and history:The Active Scripting technologies were first released in 1996, with the...

 language engines. By default it interprets and runs plain-text JScript
JScript
JScript is a scripting language based on the ECMAScript standard that is used in Microsoft's Internet Explorer.JScript is implemented as a Windows Script engine. This means that it can be "plugged in" to any application that supports Windows Script, such as Internet Explorer, Active Server Pages,...

 (.JS and .JSE files) and VBScript
VBScript
VBScript is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It is designed as a “lightweight” language with a fast interpreter for use in a wide variety of Microsoft environments...

 (.VBS and .VBE files).

Users can install different scripting engines to enable them to script in other languages, for instance PerlScript
PerlScript
PerlScript was initially solely an ActiveX Scripting Engine produced by the company ActiveState for use with Microsoft's Internet Information Services that allows for programmers to use Perl-based code in addition to, or in place of, VBScript or JScript in the context of web servers running the...

. The language independent filename extension
Filename extension
A filename extension is a suffix to the name of a computer file applied to indicate the encoding of its contents or usage....

 WSF can also be used. The advantage of the Windows Script File
Windows Script File
A Windows Script File is a file type used by the Microsoft Windows Script Host. It allows mixing the scripting languages JScript and VBScript within a single file, or other scripting languages such as Perl, Object REXX, Python, or Kixtart if installed by the user...

 (.WSF) is that it allows the user to use a combination of scripting languages within a single file.

WSH engines include various implementations for the Rexx
REXX
REXX is an interpreted programming language that was developed at IBM. It is a structured high-level programming language that was designed to be both easy to learn and easy to read...

, Basic
BASIC
BASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....

, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

, Tcl
Tcl
Tcl is a scripting language created by John Ousterhout. Originally "born out of frustration", according to the author, with programmers devising their own languages intended to be embedded into applications, Tcl gained acceptance on its own...

, PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

, JavaScript
JavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

, Delphi
Object Pascal
Object Pascal refers to a branch of object-oriented derivatives of Pascal, mostly known as the primary programming language of Embarcadero Delphi.-Early history at Apple:...

, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

, XSLT
XSLT
XSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...

, and other languages.

Windows Script Host is distributed and installed by default on Windows 98
Windows 98
Windows 98 is a graphical operating system by Microsoft. It is the second major release in the Windows 9x line of operating systems. It was released to manufacturing on 15 May 1998 and to retail on 25 June 1998. Windows 98 is the successor to Windows 95. Like its predecessor, it is a hybrid...

 and later versions of Windows. It is also installed if Internet Explorer 5
Internet Explorer 5
Microsoft Internet Explorer 5 was a graphical web browser released in March 1999 by Microsoft, primarily for Microsoft Windows, but initially with versions available for Apple Macintosh, Sun Solaris, and HP-UX. It was one of the main participants of the first browser war...

 (or a later version) is installed. Beginning with Windows 2000
Windows 2000
Windows 2000 is a line of operating systems produced by Microsoft for use on personal computers, business desktops, laptops, and servers. Windows 2000 was released to manufacturing on 15 December 1999 and launched to retail on 17 February 2000. It is the successor to Windows NT 4.0, and is the...

, the Windows Script Host became available for use with user login scripts.

Usage

Windows Script Host may be used for a variety of purposes, including logon scripts, administration and general automation. Microsoft describes it as an administration tool. WSH provides an environment for scripts to run – it invokes the appropriate script engine and provides a set of services and objects for the script to work with. These scripts may be run in either GUI
Gui
Gui or guee is a generic term to refer to grilled dishes in Korean cuisine. These most commonly have meat or fish as their primary ingredient, but may in some cases also comprise grilled vegetables or other vegetarian ingredients. The term derives from the verb, "gupda" in Korean, which literally...

 mode (WScript.exe) or command line mode (CScript.exe) offering flexibility to the user for interactive or non-interactive scripts. WSH implements an object model
Object model
In computing, object model has two related but distinct meanings:# The properties of objects in general in a specific computer programming language, technology, notation or methodology that uses them. For example, the Java objects model, the COM object model, or the object model of OMT...

 which exposes a set of COM
Component Object Model
Component Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...

 interfaces.

Examples

The first example is very simple; it shows some VBScript
VBScript
VBScript is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It is designed as a “lightweight” language with a fast interpreter for use in a wide variety of Microsoft environments...

 which uses the root WSH COM
Component Object Model
Component Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...

 object "WScript" to display a message with an 'OK' button. Upon launching this script the CScript or WScript engine would be called and the runtime environment provided.

Content of a file hello0.vbs

WScript.Echo "Hello world"
WScript.Quit


For WSH programing you can also use the JScript
JScript
JScript is a scripting language based on the ECMAScript standard that is used in Microsoft's Internet Explorer.JScript is implemented as a Windows Script engine. This means that it can be "plugged in" to any application that supports Windows Script, such as Internet Explorer, Active Server Pages,...

 language.

Content of a file hello1.js

WSH.Echo("Hello world");
WSH.Quit;


Or you can mix VBScript
VBScript
VBScript is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It is designed as a “lightweight” language with a fast interpreter for use in a wide variety of Microsoft environments...

 and JScript
JScript
JScript is a scripting language based on the ECMAScript standard that is used in Microsoft's Internet Explorer.JScript is implemented as a Windows Script engine. This means that it can be "plugged in" to any application that supports Windows Script, such as Internet Explorer, Active Server Pages,...

 (and any other) code in the same WSF
Windows Script File
A Windows Script File is a file type used by the Microsoft Windows Script Host. It allows mixing the scripting languages JScript and VBScript within a single file, or other scripting languages such as Perl, Object REXX, Python, or Kixtart if installed by the user...

 file:

Content of a file hello2.wsf






Security concerns

Windows applications and processes may be automated using a script in Windows Script Host. Viruses and malware could be written to exploit this ability. Consequently, some suggest disabling it for security reasons. Alternatively antivirus programs may offer features to control .vbs and other scripts which run in the WSH environment.

One way to address security concerns about Windows Script Host is to change the default handler for the .vbs, .vbe, .js, .jse, .wsf, .wsh file types to edit rather than run.

Since version 5.6 of WSH, scripts can be digitally signed
Digital signature
A digital signature or digital signature scheme is a mathematical scheme for demonstrating the authenticity of a digital message or document. A valid digital signature gives a recipient reason to believe that the message was created by a known sender, and that it was not altered in transit...

 programmatically using the Scripting.Signer object in a script itself, provided a valid certificate
Public key certificate
In cryptography, a public key certificate is an electronic document which uses a digital signature to bind a public key with an identity — information such as the name of a person or an organization, their address, and so forth...

 is present on the system. Alternatively, the signcode tool from the Platform SDK, which has been extended to support WSH filetypes, may be used at the command line.

By using Software Restriction Policies introduced with Windows XP, a system may be configured to execute only those scripts which have been digitally signed, thus preventing the execution of untrusted scripts.

Available scripting engines

Name Language File Extensions Availability Produced By Status Date Notes
VBScript Microsoft Visual Basic, Scripting Edition .vbs Installed by Default Microsoft default install 1999
JScript Microsoft JScript .js Installed by Default Microsoft default install 1999
PerlScript Perl .pls Available with ActiveState Perl ActiveState Freeware 1999
ooRexxScript Rexx .rxs Available with Open Object Rexx Open Object Rexx team Freeware
PythonScript Python .pys SourceForge The Pywin32 project Freeware
TclScript Tcl/Tk .tcls SourceForge ActiveState and/or third party Freeware
ActivePHPScript PHP .phps Available with PHP PHP team Freeware
RubyScript Ruby .rbs Available with Ruby Ruby team Freeware
Object Rexx engine Rexx Available with IBM ObjectRexx IBM Commercial 2002
Delphi scripting engine Delphi In some Delphi distributions or resource kits Commercial 2003

Version history

Windows Version Shipped with WSH version Last redistributable version
Windows 95 None (Separate redistributable) 5.6
Windows NT 4.0 None (Separate redistributable) 5.6
Windows 98 1.0 5.6
Windows 2000 2.0 (also known as WSH 5.1) 5.7
Windows Me 2.0 (also known as WSH 5.1) 5.6
Windows XP / Windows Server 2003 5.6 5.7
Windows Vista / Windows Server 2008 / Windows XP SP3 5.7 Not applicable
Windows 7 / Windows Server 2008 R2 5.8 Not applicable


The redistributable version of WSH version 5.6 can be installed on Windows 95/98/Me and Windows NT 4.0/2000. WSH 5.7 is downloadable for Windows 2000, Windows XP and Windows Server 2003. Recently, redistributable versions for older operating systems (Windows 9x and Windows NT 4.0) are no longer available from the Microsoft Download Center.

As of Windows XP Service Pack 3, release 5.7 is not necessary as it is included.

See also

  • HTML Components
    HTML Components
    HTML Components are a nonstandard mechanism to implement components in script as Dynamic HTML "behaviors" in the Microsoft Internet Explorer web browser. Such files typically use an .htc extension....

  • JScript.NET
  • Microsoft Script Debugger
    Microsoft Script Debugger
    Microsoft Script Debugger is relatively minimal debugger for Windows Script Host-supported scripting languages, such as VBScript and JScript. Its user interface allows the user to set breakpoints and/or step through execution of script code line by line, and examine values of variables and...

  • Shell script
    Shell script
    A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language...

  • Windows PowerShell
    Windows PowerShell
    Windows PowerShell is Microsoft's task automation framework, consisting of a command-line shell and associated scripting language built on top of, and integrated with the .NET Framework...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK