VBScript Part 1 - Introduction

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes
Loading ... Loading ...

Earn $$ with WidgetBucks!

VBScript is a scripting language. A VBScript can be executed in various ways

  • Using Windows Script Host (wscript.exe and cscript.exe). Will cover this later
  • Inside HTML page for IE Browser.
  • Other host process which allows to execute code in VBScript format (ex - HP QuickTest Pro)

Internal methods and objects
VBScript provides method and objects that can be used in the script. Internal methods are one which not dependent on the Host running the script. For Ex, below code would run fine on any of scripting host

Dim myName
myName = "Tarun Lalwani"
Dim myNameLength
myNameLength = Len(myName)
WScript Message box

WScript Message box

Above code would run fine if run in standalone VBScript, HTML or QTP
Host specific methods and objects

These methods or objects are provided by the Host running the script. Scripts using such methods are specific to the Host and can only run by them. Consider the below VBScript

Dim myName
myName = "Tarun Lalwani"
WScript.Echo myName

In the above script we are using a special object named “WScript” and a method “Echo” of that object. The code would run fine when run as a standalone script file and would produce the below message

No if we paste the same code in an HTML file and try to open the file in a IE browser

<html>
<body>
<script type="text\VBScript">
Dim myName
myName = "Tarun Lalwani"
WScript.Echo myName
</script>
</body>
</html><html></html>

The IE browser will display an error (Make sure you have unchecked the Disable Script Debugging in IE Options…Advanced Tab)

WScript object required error

WScript object required error

The reason the error is thrown is that WScript is Host specific object which is defined by the WScript.exe or CScript.exe scripting hosts. When we run the same code in IE this Host specific object does not exists. It is important to understand which methods or objects are host specific when porting scripts from one host to another (Ex VBScript to QTP Script, VBScript to HTML web page etc…)

Executing a Script

Different scripting host have different ways of running the script. In windows we can write the script in a notepad file and then save it with “vbs” extension

Script written in Notepad

Script written in Notepad


Save script as VBS

Save script as VBS

Double clicking the “Demo.vbs” file in explorer execute the script. By default windows is configured to execute the script using WScript.exe

Running the script by double clicking in explorer

Running the script by double clicking in explorer

Another way to the run the script is through windows run window or command prompt. Below screenshot shows how to execute a script using cscript.exe from console.

Script executed using CScript thorugh DOS command line

Script executed using CScript thorugh DOS command line

For an IE host we would need to run the HTML file containing the code which in turn would.

Have questions related to this article? Want to request a new article? Use our forums to post your questions


Viewed 5,082 times

Related posts:


    Support KnowledgeInbox (Why donate?)




    Your Email Address:



  1. Most Viewed


  2. Sitemap

    open all | close all
  3. Most Downloaded

    • Screen Capture and Comparion API - Version 1.1.1 (425.5 KiB, 5,586 hits)
      You need to be a registered user to download this file.
    • QTP Clean uninstaller (26.4 KiB, 5,005 hits)
      You need to be a registered user to download this file.
    • VB to QTP API Converter (37.2 KiB, 4,393 hits)
      You need to be a registered user to download this file.
    • IE Helper setup (3.5 MiB, 4,132 hits)
      You need to be a registered user to download this file.
    • Dynamic Action Call Demo - Part 1 (40 KiB, 3,643 hits)
      You need to be a registered user to download this file.
  4. Most Rated

  5. Translator

    English flagItalian flagKorean flagChinese (Simplified) flagPortuguese flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flag
    Croat flagDanish flagFinnish flagHindi flagPolish flagRumanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flag
    Slovak flagSlovenian flagUkrainian flagVietnamese flag           
    By N2H
  6. Last searched terms

    Last referers

    Visitors Online



Your Ad Here