Spread the love

What is Windows Script Host (WSH)?

Spread the love

Windows Script Host (WSH)?
Windows Script Host (WSH)?

What is the Windows Script Host (WSH)?

In this post, I will cover the windows script host (wsh) tutorial in step by step manner. By technology, it is a program that runs within the Windows environment and acts as a container to run VBScript files. It is a Windows administration tool. WSH creates an environment for hosting scripts. That is, when a script arrives at your computer, WSH plays the part of the host.

READ  How To Decrypt a URL or String In VbScript or UFT

It makes objects and services available for the script and provides a set of guidelines within which the script is executed. Among other things, Windows Script Host manages security and invokes the appropriate script engine. Windows Script Host is built into Microsoft Windows 98, 2000, and Millennium Editions and higher versions.

A Windows script is a text file. We can create a script with any text editor as long as we save our script with a WSH-compatible script extension (.js, VBS, or .wsf).WSH also supports to write scripts in JScript, Perl, Python, REXX, other ActiveX scripting languages including VBScript.

READ  Control Flow in VBScript or UFT

Refer here for more details for WSH. I am highly encouraged by this site. This post is a lighter version of the same mostly applicable for UFT.

by writing a WSH script we can take advantage of ADSI and WMI. We will discuss these within a while.

List of Supporting technologies

 

ExtensionsDescription
.batMSDOS batch file
.aspASP pages
.htmHTML Webpages
.htmlHTML Webpages
.jsjscript file
.vbsVbScript file
.wshWindows Script host files
.wsfWindows Script host files

Common Editor for WSH Scripts

The most commonly available text editor is already installed on our computer ? Notepad. We can also use your favorite HTML editor, VbsEdit, Microsoft Visual C++, or Visual InterDev.

Below are the popular VBScript /VBS editors

There are hundreds of Text editor available for WSH scripts to write VbScript, VBS code. Below are my choices:

From where to download WSH

WSH can be downloaded fromĀ here.

How to Write Code for WSH or VBScript or VBS

Creating a script with Notepad

  1. Start Notepad.
  2. Write your script. For example purposes, type Msgbox “Hello VB Script”
  3. Save this text file with a .vbs extension (instead of the default .txt extension). For example, Hello.vbs
  4. Navigate to the file you just saved, and double-click it.
  5. Windows Script Host invokes the VB Script engine and runs your script. In the example, a message box is displayed with the message “Hello VB Script”
  6. Hosting Environments and Script Engines
READ  How to Work with Windows Registry with WSH?

Scripts are often embedded in Web pages, either in an HTML page (on the client-side) or in an ASP page (on the server-side).In the case of a script embedded in an HTML page, the engine component that interprets and runs the script code is loaded by the Web browser, such as Internet Explorer. In the case of a script embedded in an ASP page, the engine that interprets and runs the script code is built into Internet Information Services (IIS). Windows Script Host executes scripts that exist outside an HTML or ASP page and that stand on their own as text files.

READ  Signed and Unsigned ActiveX Controls

How to Run WSH Scripts

We can execute WSH Scripts in the following manners:
  1. Using command-line. It uses Cscript.exe. It is used in the MSDOS console window.
  2. Within Windows like double click on the script file. It uses WScript.exe. It is used in Windows GUI.

Cscript commands


Cscript<filepath><filename>.<extension>

we can pass arguments to the Cscript as well:


Cscript<filepath><filename>.<extension> [Options...][Argument1],....[ArgumentN]

If we run CScript.exe without any arguments , directly from the command line, we can get the usage notes.

The switches available to run a Cscripts are as follows:

Option/SwitchDescription
//BBatch mode on Suppress the errors and prompts
//DEnable debugging
//E:engineExecutes scripts by using the engine
//H:CscriptChanges the host to Csript
//H: WscriptChanges the host to Wscript
//IActivates interactive mode
//Job:XXXExecutes a WSF job
//LogoActivates and display a Logo
//NoLogoDeactivate logo display
//SSaves the command-line options for an active user
//T:nnSets time out in Seconds. A script can run ‘nn’ seconds. Post this time out the script just aborts
//XRun the script in Debugger mode
//UActivates Unicode for redirecting IO from the console

Execute WSH using WScript.exe

Similarly, we can execute WSH scripts in the Windows environment using WScript.exe.

  • The execution begins once we double click on the file. In this case, the file has to be registered with WSH.
  • We can also use a Run command with the full path of the script and script name
READ  Control Flow in VBScript or UFT

like-

wscript c:\Test\TestScriptName.vbs

However, if we run WScript from the command prompt, instead of getting output, we will get a configuration box for script customization options. If Ok is clicked after providing all customization options, It won’t run. It just saves the individual configurations for the script.

What is the difference between CScript.Exe and WScript.Exe?

The difference comes to existence when we debug a script. CScript.exe sends the error message directly to the console which is very convenient to use. Whereas WScript.exe shows the errors in the form of popup. So handling the huge number of popups would be tedious.

So while debugging we need to use CScript.exe and while running we need to use WScript.exe with Echo() method enabled.

How to create a .WSH file?

In order to create a .WSh file, we select a file that is currently associated with WScript(.js,.VBS,.wsf etc) then right-click on that.

READ  Web site Efficiency and Load Screening

Once the Properties dialog opens, navigate to different tabs. It will allow us to change the default configurations. We can make changes to them and can apply the changes. This will create a new .wsh file with the same script name.

It will be like below:

[ScriptFile]
Path=D:\test\myTest.vbs
[Options]
Timeout=30
...
...




Spread the love
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn File System Object(FSO) in UFT or QTP or VBScript Free

This post will cover the File System Object(FSO) in UFT. File...

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...

EDITOR PICKS


Spread the love