All Topics  
VBScript

 

   Email Print
   Bookmark   Link






 

VBScript



 
 
VBScript (short for Visual Basic Scripting Edition) is an Active Scripting
Active Scripting

Active Scripting is the technology used in Microsoft Windows to implement component-based scripting support. It is based on Component Object Model and allows installation of additional scripting engines in the form of COM modules....
 language, developed by Microsoft
Microsoft

Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices....
, which uses the Component Object Model
Component Object Model

Component Object Model is an 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....
 to access elements of the environment within which it's running (e.g. FileSystemObject or FSO
FSO

FSO may stand for:* Fabryka Samochod?w Osobowych, a Poland passenger car company* Federal Protective Service of Russia responsible for the security of Russian state officials....
 used to create, read, update and delete files
Computer file

A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable computer storage....
). The language's syntax reflects its origins as a limited variation of Microsoft's Visual Basic
Visual Basic

'Visual Basic' is the third-generation programming language event-driven programming and integrated integrated development environment from Microsoft for its Component Object Model programming model....
 programming language.

VBScript has been installed by default in every desktop release of Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
 since Windows 98
Windows 98

Windows 98 is a graphical operating system released on 25 June 1998 by Microsoft and the successor to Windows 95. Like its predecessor, it is a hybrid 16-bit application/32-bit application monolithic product based on MS-DOS....
; as part of Windows Server
Windows Server

Windows Server is a brand name for server operating systems released by Microsoft Corporation. This name has been used for the following software releases:...
 since Windows NT 4.0 Option Pack
Windows NT 4.0

Windows NT 4.0 is a Preemption , Graphical user interface and business-oriented operating system designed to work with either uniprocessor or Symmetric multiprocessing computers....
; and optionally with Windows CE
Windows CE

Windows CE is Microsoft's operating system for minimalistic computers and embedded systems. Windows CE is a distinctly different operating system and Kernel , rather than a trimmed-down version of desktop Windows....
 (depending on the device it is installed on).

A VBScript script must be executed within a host environment, of which there are several provided with Microsoft Windows, including: Windows Script Host
Windows Script Host

The Microsoft Windows Script Host is an automation technology for Microsoft Windows operating systems that provides scripting capabilities comparable to batch files, but with a greater range of supported features....
 (WSH), Internet Explorer
Internet Explorer

Windows Internet Explorer , commonly abbreviated to IE, is a series of graphical user interface web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems starting in 1995....
 (IE), Internet Information Services
Internet Information Services

Internet Information Services - formerly called Internet Information Server - is a set of Internet-based services for servers created by Microsoft for use with Microsoft Windows....
 (IIS).






Discussion
Ask a question about 'VBScript'
Start a new discussion about 'VBScript'
Answer questions from other users
Full Discussion Forum



Encyclopedia


VBScript (short for Visual Basic Scripting Edition) is an Active Scripting
Active Scripting

Active Scripting is the technology used in Microsoft Windows to implement component-based scripting support. It is based on Component Object Model and allows installation of additional scripting engines in the form of COM modules....
 language, developed by Microsoft
Microsoft

Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices....
, which uses the Component Object Model
Component Object Model

Component Object Model is an 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....
 to access elements of the environment within which it's running (e.g. FileSystemObject or FSO
FSO

FSO may stand for:* Fabryka Samochod?w Osobowych, a Poland passenger car company* Federal Protective Service of Russia responsible for the security of Russian state officials....
 used to create, read, update and delete files
Computer file

A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable computer storage....
). The language's syntax reflects its origins as a limited variation of Microsoft's Visual Basic
Visual Basic

'Visual Basic' is the third-generation programming language event-driven programming and integrated integrated development environment from Microsoft for its Component Object Model programming model....
 programming language.

VBScript has been installed by default in every desktop release of Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
 since Windows 98
Windows 98

Windows 98 is a graphical operating system released on 25 June 1998 by Microsoft and the successor to Windows 95. Like its predecessor, it is a hybrid 16-bit application/32-bit application monolithic product based on MS-DOS....
; as part of Windows Server
Windows Server

Windows Server is a brand name for server operating systems released by Microsoft Corporation. This name has been used for the following software releases:...
 since Windows NT 4.0 Option Pack
Windows NT 4.0

Windows NT 4.0 is a Preemption , Graphical user interface and business-oriented operating system designed to work with either uniprocessor or Symmetric multiprocessing computers....
; and optionally with Windows CE
Windows CE

Windows CE is Microsoft's operating system for minimalistic computers and embedded systems. Windows CE is a distinctly different operating system and Kernel , rather than a trimmed-down version of desktop Windows....
 (depending on the device it is installed on).

A VBScript script must be executed within a host environment, of which there are several provided with Microsoft Windows, including: Windows Script Host
Windows Script Host

The Microsoft Windows Script Host is an automation technology for Microsoft Windows operating systems that provides scripting capabilities comparable to batch files, but with a greater range of supported features....
 (WSH), Internet Explorer
Internet Explorer

Windows Internet Explorer , commonly abbreviated to IE, is a series of graphical user interface web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems starting in 1995....
 (IE), Internet Information Services
Internet Information Services

Internet Information Services - formerly called Internet Information Server - is a set of Internet-based services for servers created by Microsoft for use with Microsoft Windows....
 (IIS). Additionally, The VBScript hosting environment is embeddable in other programs, through technologies such as the Microsoft Script control (msscript.ocx).

History


VBScript began as part of the Microsoft Windows Script Technologies, which were launched in 1996, initially targeted at web developers. During a period of just over two years, the VBScript and JScript languages advanced from version 1.0 to 2.0, and over that time it gained support from Windows system administrator
System administrator

A system administrator, systems administrator, or sysadmin, is a person employed to maintain and operate a computer system and/or computer network....
s seeking an automation tool more powerful than the batch language
Batch file

In DOS, OS/2, and Microsoft Windows, a batch file is a text file containing a series of Command intended to be executed by the Command line interpreter....
 first developed in the late 1970s.

In version 5.0, the functionality of VBScript was increased with new features such as: regular expression
Regular expression

In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters....
s; classes
Class (computer science)

In object-oriented programming, a class is a programming language construct that is used as a blueprint to create Object s. This blueprint includes Attribute s and Method s that the created objects all share....
; the With statement; the Eval, Execute, and ExecuteGlobal functions to evaluate and execute script commands built during the execution of another script; a function-pointer system via GetRef, and Distributed COM (DCOM) support.

In version 5.5, SubMatches were added to the regular expression class in VBScript, to finally allow VBScript script authors to capture the text within the expression's groups. That capability before was only possible through JScript
JScript

JScript is the Microsoft dialect of the ECMAScript scripting language specification.JavaScript , JScript, and ECMAScript are very similar languages....
.

With the advent of the .NET framework
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
, the scripting team took the decision to implement future support for VBScript within ASP.NET
ASP.NET

ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites, web applications and web services....
 for web development, and therefore no new versions of the VBScript engine would be developed and it moved over to being supported by Microsoft's Sustaining Engineering Team, who are responsible for bug fixes and security enhancements. For Windows system administrators, the suggestion is that they migrate to using Windows PowerShell
Windows PowerShell

Windows PowerShell is an extensible command line interface shell and associated scripting language from Microsoft. It was released in 2006 and is currently available for Windows XP SP2/SP3, Windows Server 2003, Windows Vista and is included in Windows Server 2008 as well as Windows 7 as an optional feature....
. However version 5.6 of the scripting engine will continue to be shipped with future releases of Microsoft Windows and IIS.

Uses


When employed in Microsoft Internet Explorer
Internet Explorer

Windows Internet Explorer , commonly abbreviated to IE, is a series of graphical user interface web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems starting in 1995....
, VBScript is similar in function to JavaScript
JavaScript

JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard....
, as a language to write functions that are embedded in or included from HTML pages and interact with the Document Object Model
Document Object Model

The Document Object Model is a platform- and programming language-independent standard object model for representing HTML or XML documents as well as an Application Programming Interface for querying, traversing and manipulating such documents....
 (DOM) of the page, to perform tasks not possible in HTML alone. Other web browsers such as Firefox, and Opera
Opera (web browser)

Opera is a web browser and Internet suite developed by the Opera Software company. Opera handles common Internet-related tasks such as displaying web sites, sending and receiving e-mail messages, managing contacts, IRC online chatting, downloading files via BitTorrent , and reading web feeds....
 do not have built-in support for VBScript. This means that where client-side script is required on a web site, developers almost always use JavaScript for cross-browser compatibility.

Besides client-side web development, VBScript is used for server-side processing of web pages, most notably with Microsoft Active Server Pages
Active Server Pages

Active Server Pages , also known as Classic ASP, was Microsoft's first server-side scripting Active Scripting for dynamic web page. Initially released as an add-on to Internet Information Services via the Windows_NT_4.0#Option_Pack, it was subsequently included as a free component of Windows Server ....
 (ASP). The ASP engine and type library, asp.dll, invokes vbscript.dll to run VBScript scripts. VBScript that is embedded in an ASP page is contained within <% and %> context switches. The following example of an ASP page with VBScript displays the current time in 24-hour format (Note that an '=' sign occurring after a context switch (<%) is short-hand for a call to Write method of the Response object).

<% Option Explicit %> VBScript Example <% 'Grab current time from Now function. Dim timeValue timeValue = Now %> The time, in 24-hour format, is <%=Hour(timeValue)%>:<%=Minute(timeValue)%>:<%=Second(timeValue)%>. VBScript can also be used to create applications that run directly on a person's computer running Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
. The simplest example of this is a script that makes use of the Windows Script Host
Windows Script Host

The Microsoft Windows Script Host is an automation technology for Microsoft Windows operating systems that provides scripting capabilities comparable to batch files, but with a greater range of supported features....
 (WSH) environment. Such a script is usually in a stand-alone file with the file extension .vbs. The script can be invoked in two ways. Wscript.exe is used to display output and receive input in through a GUI, such as dialog and input boxes. Cscript.exe is used in a command line environment
Command line interface

A command-line interface is a mechanism for interacting with a computer operating system or software by typing commands to perform specific tasks....
.

VBScript .vbs files can be included in two other types of scripting files: .wsf files, which are styled after XML; and .hta files, which are styled after HTML. .wsf files can be executed using wscript.exe or cscript.exe, just like .vbs files, and .wsf files can include multiple .vbs files. As a result .wsf files provide a means for code reuse: one can write a library of classes or functions in one or more .vbs files, and include those files in one or more .wsf files to use and reuse that functionality in a modular way.

Another employment of VBScript is the HTML Application
HTML Application

An HTML Application is a Microsoft Windows application written with HTML and Dynamic HTML. The ability to write HTAs was introduced with Microsoft Internet Explorer 5.0....
, or HTA (file extension .hta). In an HTA, HTML is used for the user interface, and a scripting language such as VBScript is used for the program logic. HTAs run inside of mshta.exe, which is a 'Trusted Application Environment' provided by Internet Explorer
Internet Explorer

Windows Internet Explorer , commonly abbreviated to IE, is a series of graphical user interface web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems starting in 1995....
. The 'Trusted Application Environment', implies that HTAs do not suffer the restrictions applied to applications running in the web or intranet zone, such as accessing local files or network paths. Although HTAs run in this 'trusted' environment, querying Active Directory
Active Directory

Active Directory is a technology created by Microsoft that provides a variety of network services, including:* Lightweight Directory Access Protocol-like directory services...
 can be subject to Internet Explorer
Internet Explorer

Windows Internet Explorer , commonly abbreviated to IE, is a series of graphical user interface web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems starting in 1995....
 Zone logic and associated error messages.

VBScript (and JScript) can be used in a .wsc file to create a Windows Script Component - an ActiveX-enabled script class that can be invoked by other COM
Component Object Model

Component Object Model is an 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....
-enabled applications.

Lastly, VBScript has been adopted as the internal scripting language for some embedded applications, such as industrial operator interfaces and human machine interfaces.

Functionality


As-is, VBScript provides functions and sub-routines, basic date/time, string manipulation, math, user interaction, error handling, and regular expressions. Additional functionality can be added through the use of ActiveX technologies. File system management, file modification, and streaming text operations can be achieved with the Scripting Runtime Library scrrun.dll. Binary file and memory I/O is provided by the "ADODB.Stream" class, which can also be used as a string builder (since a high amount of VBScript string concatenation is costly due to constant memory re-allocation), and can be used to convert an array of bytes to a string and vice versa. Database access is made possible through ActiveX Data Objects
ActiveX Data Objects

Microsoft's ActiveX Data Objects is a set of Component Object Model object s for accessing data sources. It provides a Abstraction layer between programming languages and OLE DB ....
 (ADO), and the IIS Metabase
Metabase

Microsoft's Internet Information Services stores its information in an internal database called the MetaBase. The metabase is an inheritable, hierarchical database that allows for configuration of []/[], File Transfer Protocol, Simple Mail Transfer Protocol, and Network News Transfer Protocol at the server, the site, or the folder or file le...
 can be manipulated using the GetObject function with sufficient permissions (useful for creating and destroying sites and virtual directories). Additionally, XML files and schemas can be manipulated with the Microsoft XML Library
MSXML

Microsoft XML Core Services is a set of services that allow applications written in JScript, VBScript, and Microsoft development tools to build Windows-native XML-based applications....
 Application Programming Interface
Application programming interface

An application programming interface is a set of subroutine, data structures, class and/or Protocol provided by library and/or operating system Service s in order to support the building of applications....
s (msxml6.dll, msxml3.dll), which also can be used to retrieve content from the World Wide Web via the XMLHTTP and ServerXMLHTTP objects (class strings "MSXML2.XMLHTTP.6.0" and "MSXML2.ServerXMLHTTP.6.0").

See also


  • JScript
    JScript

    JScript is the Microsoft dialect of the ECMAScript scripting language specification.JavaScript , JScript, and ECMAScript are very similar languages....
  • JavaScript
    JavaScript

    JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard....
  • PHP
    PHP

    PHP is a scripting language originally designed for producing dynamic web pages. It has evolved to include a command line interface capability and can be used in Standalone software Graphical user interface....
  • JScript.NET
  • Windows Script File
    Windows Script File

    A Windows Script File is a file type used by the Microsoft Windows Script Host. It allows mixing scripting languages such as Perl, Object REXX, Python , Kixtart, JScript, and VBScript within a single file....
  • HTML Components
    HTML Components

    HTML Components are a mechanism to implement components in script as Dynamic HTML "behaviors".. Such files typically use a .htc extension.HTC is typically an HTML file and a set elements that define the component....


External links


  • in the Microsoft Developer Network