VBScript

Last updated
VBScript
VBSccript file format icon.png
Developer Microsoft
First appeared1996;27 years ago (1996)
Stable release
5.8
OS Windows
Filename extensions .vbs, .vbe, .wsf, .wsc (.asp, .hta, .htm, .html)
Website docs.microsoft.com/en-us/previous-versions/t0aew7h6(v=vs.85)
Major implementations
Windows Script Host, Active Server Pages
Influenced by
Visual Basic
Influenced
Windows PowerShell

VBScript ("Microsoft Visual Basic Scripting Edition") is a deprecated Active Scripting language developed by Microsoft that is modeled on Visual Basic. It allows Microsoft Windows system administrators to generate powerful tools for managing computers without error handling and with subroutines and other advanced programming constructs. It can give the user complete control over many aspects of their computing environment.

Contents

VBScript uses the Component Object Model to access elements of the environment within which it is running; for example, the FileSystemObject (FSO) is used to create, read, update and delete files. VBScript has been installed by default in every desktop release of Microsoft Windows since Windows 98; [1] in Windows Server since Windows NT 4.0 Option Pack; [2] and optionally with Windows CE (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 (WSH), Internet Explorer (IE), and Internet Information Services (IIS). [3] 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, launched in 1996. This technology (which also included JScript) was initially targeted at web developers. During a period of just over two years, VBScript advanced from version 1.0 to 2.0, and over that time it gained support from Windows system administrators seeking an automation tool more powerful than the batch language first developed in the early 1980s. [4] On August 1, 1996, Internet Explorer was released with features that included VBScript. [5]

In version 5.0, the functionality of VBScript was increased with new features including regular expressions; classes; the With statement; [6] 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, [7] and Distributed COM (DCOM) support.

In version 5.5, SubMatches [8] were added to the regular expression class in VBScript, to finally allow script authors to capture the text within the expression's groups. That capability had already been available in JScript.

With the advent of the .NET Framework, the scripting team took the decision to implement future support for VBScript within ASP.NET for web development, [9] and therefore no new versions of the VBScript engine would be developed. It would henceforth be supported by Microsoft's Sustaining Engineering Team, who are responsible for bug fixes and security enhancements. For Windows system administrators, Microsoft suggests migrating to Windows PowerShell, as VBScript is deprecated and will eventually be removed from Windows.

On October 9, 2023, Microsoft announced plans to deprecate and eventually remove VBScript from future Windows versions. [10]

Environments

When employed for client-side web development in Microsoft Internet Explorer, VBScript is similar in function to JavaScript. It is used to write executable functions that are embedded in or included from HTML pages and interact with the Document Object Model (DOM) of the page, to perform tasks not possible in HTML alone. However, other web browsers such as Firefox and Opera and recently Chrome do not have built-in support for VBScript. This means that where client-side scripting and cross-browser compatibility are required, developers usually choose JavaScript over most other programming languages, such as VBScript.

VBScript is also used for server-side processing of web pages, most notably with Microsoft Active Server Pages (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, but it is also used as the default script for error messages with the Windows operating systems.

<%OptionExplicit%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>VBScriptExample</title></head><body><div><%' Grab current time from Now() function.' An '=' sign occurring after a context switch (<%) is shorthand ' for a call to the Write() method of the Response object.DimtimeValue:timeValue=Now%>Thetime,in24-hourformat,is<%=Hour(timeValue)%>:<%=Minute(timeValue)%>:<%=Second(timeValue)%>. </div></body></html>

VBScript can also be used to create applications that run directly on a workstation running Microsoft Windows. The simplest example is a script that makes use of the Windows Script Host (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 through a GUI, such as dialog and input boxes. Cscript.exe is used in a command line environment.

VBScript can be included in two other types of scripting files: Windows Script Files, and HTML Applications.

A Windows Script File (WSF) is styled after XML. A WSF file can include multiple VBS files. As a result, WSF files provide a means for code reuse: a library of classes or functions can be stored in one or more .vbs files, which can be included in .wsf files, so the functionality can be reused in a modular way. The files have extension .wsf and can be executed using wscript.exe or cscript.exe, just as a .vbs file can.

An HTML Application (HTA) is styled after HTML. The HTML in the file is used to generate the user interface, and a scripting language such as VBScript is used for the program logic. The files have extension .hta and can be executed using mshta.exe.

VBScript (and JScript) can also be used in a Windows Script Component, an ActiveX-enabled script class that can be invoked by other COM-enabled applications. [11] These files have extension .wsc.

VBScript is simple to create and can be coded using an easy to use text editor like Notepad. A simple VBScript saved by the .vbs extension can be run on a Windows system by double clicking it.

Functionality

Language features

The language of VBScript is modeled on Visual Basic, and therefore can be reviewed using similar categories: procedures, control structures, constants, variables, user interaction, array handling, date/time functions, error handling, mathematical functions, objects, regular expressions, string manipulation, and so on. [12]

The following are some key points of introduction to the VBScript language by Microsoft

A "procedure" is the main construct in VBScript for separating code into smaller modules. VBScript distinguishes between a function, which can return a result in an assignment statement, and a subroutine, which cannot. Parameters are positional, and can be passed by value or by reference.

Control structures include the usual iterative and conditional Do Loops, If-Then-Else statements, and Case statements, with some more complex variants, such as ElseIf and nested control structures.

As a memory aid in coding, and certainly for readability, there are a large number of constants, such as True and False for logical values, vbOKCancel and vbYesNo for MsgBox codes, vbBlack and vbYellow for color values, vbCR for the carriage return character, and many others.

Variables have "Variant" type by default, but it is possible (and sometimes necessary) to force a particular type (integer, date, etc.) using conversion functions (CInt, CDate, etc.)

User interaction is provided through the functions MsgBox and InputBox which provide a simple dialogue box format for messages and input. Both functions display prompting messages, with the former returning a standard response, and the latter returning one user-supplied text or numeric value. For more elaborate GUI interaction with controls, VBScript can be used in combination with HTML, for example, in an HTML Application. Event-driven forms are not supported as in Visual Basic or Visual Basic for Applications.

Names are not case-sensitive. However, it is considered a best practice of VBScript style to be consistent and to capitalize judiciously.

VBScript functionalities

When hosted by the Windows Script Host, VBScript provides numerous features which are common to scripting languages, but not available from Visual Basic 6.0. These features include direct or easy access to:

CScript, the command line runner, provides options for:

Additional functionality

File system management, file modification, and streaming text operations are implemented with the Scripting Runtime Library scrrun.dll. This provides objects such as FileSystemObject, File, and TextStream, which expose the Windows file system to the programmer.

Binary file and memory I/O are provided by the "ADODB.Stream" class, which can also be used for string builders (to avoid excessive string concatenation, which can be costly), and to interconvert byte arrays and strings. Database access is made possible through ActiveX Data Objects (ADO), and the IIS Metabase can be manipulated using the GetObject() function with sufficient permissions (useful for creating and destroying sites and virtual directories). XML files and schemas can be manipulated with the Microsoft XML Library Application Programming Interfaces (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", respectively).

Functionality can also be added through ActiveX technologies. Security concerns have led to many ActiveX controls being blacklisted in the Internet Explorer process by Microsoft, which deploys the killbit via monthly Windows security updates to disable vulnerable Microsoft and third party code. [13] [14]

Programmers can utilize the extensibility via COM (ActiveX) modules to specifically equip the Script Host and VBScript with required or desired functions. The "VTool" component, for instance, adds a number of dialog windows, binary file access, and other functionality. [15]

Development tools

Microsoft does not routinely make available an IDE (Integrated Development Environment) for VBScript, although the Microsoft Script Editor has been bundled with certain versions of Microsoft Office.

For debugging purposes the Microsoft Script Debugger can still be used in current Windows versions, even though the tool has not been updated in years. It allows the user to set break points in the VBScript code but the user interface is more than clumsy.

There are VBScript debuggers available from third-party sources, [16] [17] and many text editors offer syntax highlighting for the language.

During execution, when an error occurs, the script host issues a message stating the type of error and the number of the offending line.

Uses

Although VBScript is a general-purpose scripting language, several particular areas of use are noteworthy. First, it used to be widely used among system administrators in the Microsoft environment, [18] but it has since been vastly surpassed by PowerShell. Second, VBScript is the scripting language for Micro Focus Unified Functional Testing, a test automation tool. [19] A third area to note is the adoption of VBScript as the internal scripting language for some embedded applications, such as industrial operator interfaces and human machine interfaces. The hierarchical DBMS InterSystems Caché (which has its roots in the language MUMPS) also supports an implementation of VBScript, Cache BASIC, for programming stored code. [20]

VBScript omits several useful features of the full Visual Basic, such as strong typing, extended error trapping and the ability to pass a variable number of parameters to a subroutine. However, its use is relatively widespread because it is easy to learn and because those who implement code in the language need not pay royalties to Microsoft as long as the VBScript trade mark is acknowledged.[ citation needed ] When an organization licenses Visual Basic for Applications (VBA) from Microsoft, as companies such as Autodesk, StatSoft, Great Plains Accounting and Visio (subsequently acquired by Microsoft) have done, it is allowed to redistribute the full VBA code-writing and debugging environment with its product.

VBScript is used in place of VBA as the macro language of Outlook 97.

VBScript can be effectively used for automating day to day office tasks as well as monitoring in the Windows-based environment. It can also be used in collaboration with ADODB ActiveX Data Objects (ADODB) for effective database connectivity.

VBScript can also be used to create malware and viruses, such as the ILOVEYOU worm that spread through email attachment in Outlook 97 that cost billions of dollars.

Deprecation and Removal from Windows

In October of 2023, Microsoft announced that VBScript is deprecated in Windows and is slated to be removed in a future release. [21]


See also

Related Research Articles

Visual Basic for Applications (VBA) is an implementation of Microsoft's event-driven programming language Visual Basic 6.0 built into most desktop Microsoft Office applications. Although based on pre-.NET Visual Basic, which is no longer supported or updated by Microsoft, the VBA implementation in Office continues to be updated to support new Office features. VBA is used for professional and end-user development due to its perceived ease-of-use, Office's vast installed userbase, and extensive legacy in business.

JScript is Microsoft's legacy dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer web browser.

<span class="mw-page-title-main">Windows Script Host</span> Automation Technology for Windows

The Microsoft Windows Script Host (WSH) is an automation technology for Microsoft Windows operating systems that provides scripting abilities comparable to batch files, but with a wider range of supported features. This tool was first provided on Windows 95 after Build 950a on the installation discs as an optional installation configurable and installable by means of the Control Panel, and then a standard component of Windows 98 and subsequent and Windows NT 4.0 Build 1381 and by means of Service Pack 4. The WSH is also a means of automation for Internet Explorer via the installed WSH engines from IE Version 3.0 onwards; at this time VBScript became means of automation for Microsoft Outlook 97. The WSH is also an optional install provided with a VBScript and JScript engine for Windows CE 3.0 and following and some third-party engines including Rexx and other forms of Basic are also available.

Windows Presentation Foundation (WPF) is a free and open-source graphical subsystem originally developed by Microsoft for rendering user interfaces in Windows-based applications. WPF, previously known as "Avalon", was initially released as part of .NET Framework 3.0 in 2006. WPF uses DirectX and attempts to provide a consistent programming model for building applications. It separates the user interface from business logic, and resembles similar XML-oriented object models, such as those implemented in XUL and SVG.

WinDbg is a multipurpose debugger for the Microsoft Windows computer operating system, distributed by Microsoft. Debugging is the process of finding and resolving errors in a system; in computing it also includes exploring the internal operation of software as a help to development. It can be used to debug user mode applications, device drivers, and the operating system itself in kernel mode.

Active Scripting is the technology used in Windows to implement component-based scripting support. It is based on OLE Automation and allows installation of additional scripting engines in the form of COM modules.

Dynamic-link library (DLL) is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems. These libraries usually have the file extension DLL, OCX, or DRV . The file formats for DLLs are the same as for Windows EXE files – that is, Portable Executable (PE) for 32-bit and 64-bit Windows, and New Executable (NE) for 16-bit Windows. As with EXEs, DLLs can contain code, data, and resources, in any combination.

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 properties after any step. In effect, it provides a way for developers to see script code behavior as it runs, thus eliminating much of the guess-work when things do not quite work as intended.

In Microsoft Windows applications programming, OLE Automation is an inter-process communication mechanism created by Microsoft. It is based on a subset of Component Object Model (COM) that was intended for use by scripting languages – originally Visual Basic – but now is used by several languages on Windows. All automation objects are required to implement the IDispatch interface. It provides an infrastructure whereby applications called automation controllers can access and manipulate shared automation objects that are exported by other applications. It supersedes Dynamic Data Exchange (DDE), an older mechanism for applications to control one another. As with DDE, in OLE Automation the automation controller is the "client" and the application exporting the automation objects is the "server".

Microsoft XML Core Services (MSXML) are set of services that allow applications written in JScript, VBScript, and Microsoft development tools to build Windows-native XML-based applications. It supports XML 1.0, DOM, SAX, an XSLT 1.0 processor, XML schema support including XSD and XDR, as well as other XML-related technologies.

The Microsoft Windows operating system supports a form of shared libraries known as "dynamic-link libraries", which are code libraries that can be used by multiple processes while only one copy is loaded into memory. This article provides an overview of the core libraries that are included with every modern Windows installation, on top of which most Windows applications are built.

A Windows Script File (WSF) 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. These types of scripts may also be used to link many other external scripts together using a src parameter on the <script> tag in a manner similar to HTML. Windows Script Files have the extension ".WSF". A WSF makes reference to each script module in a very basic XML hierarchy as shown below, adhering to those standards outside the <script> tags. Literal use of "</script>" or "<script>" inside your <script> tags and similar challenges can be handled by the use of CDATA, as shown within the examples.

<span class="mw-page-title-main">Visual Basic (classic)</span> Event-driven programming language

The original Visual Basic is a third-generation event-driven programming language from Microsoft known for its Component Object Model (COM) programming model first released in 1991 and declared legacy during 2008. Microsoft intended Visual Basic to be relatively easy to learn and use. Visual Basic was derived from BASIC and enables the rapid application development (RAD) of graphical user interface (GUI) applications, access to databases using Data Access Objects, Remote Data Objects, or ActiveX Data Objects, and creation of ActiveX controls and objects.

An HTML Application (HTA) is a Microsoft Windows program whose source code consists of HTML, Dynamic HTML, and one or more scripting languages supported by Internet Explorer, such as VBScript or JScript. The HTML is used to generate the user interface, and the scripting language is used for the program logic. An HTA executes without the constraints of the internet browser security model; in fact, it executes as a "fully trusted" application.

ActivePerl is a distribution of Perl from ActiveState for Windows, macOS, Linux, Solaris, AIX and HP-UX.

<span class="mw-page-title-main">Visual Studio</span> Code editor and IDE

Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platforms such as Windows API, Windows Forms, Windows Presentation Foundation, Windows Store and Microsoft Silverlight. It can produce both native code and managed code.

Component Object Model (COM) is a binary-interface standard for software components introduced by Microsoft in 1993. It is used to enable inter-process communication object creation in a large range of programming languages. COM is the basis for several other Microsoft technologies and frameworks, including OLE, OLE Automation, Browser Helper Object, ActiveX, COM+, DCOM, the Windows shell, DirectX, UMDF and Windows Runtime. The essence of COM is a language-neutral way of implementing objects that can be used in environments different from the one in which they were created, even across machine boundaries. For well-authored components, COM allows reuse of objects with no knowledge of their internal implementation, as it forces component implementers to provide well-defined interfaces that are separated from the implementation. The different allocation semantics of languages are accommodated by making objects responsible for their own creation and destruction through reference-counting. Type conversion casting between different interfaces of an object is achieved through the QueryInterface method. The preferred method of "inheritance" within COM is the creation of sub-objects to which method "calls" are delegated.

<span class="mw-page-title-main">Scripting language</span> Programming language for run-time events

A scripting language or script language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. Scripting languages are usually interpreted at runtime rather than compiled.

The Microsoft Script Editor is an optional tool included in Microsoft Office 2000 through Office 2007 and is found in "%ProgramFiles%\Microsoft Office\OFFICE11" directory for Office 2003 and in "%CommonProgramFiles%" directory for other Offices.

WinWrap Basic (WWB) by Polar Engineering, Inc. is a third-party macro language based on Visual Basic used with programmes of various types which its vendor touts as an alternative to ActiveX, Visual Basic for Applications, and VSTA for this purpose. The WWB software package is used in conjunction with Microsoft development tools including Visual Studio, Visual Studio.NET, and the ActiveX scripting engines. The default file extension for programmes written in this language is .wwb.

References

  1. WSH Version Information, on MSDN
  2. VBScript Version Information, on MSDN
  3. What is VBScript?, in MSDN Library
  4. 86-DOS
  5. "The History of Visual Basic". www.johnsmiley.com.
  6. Visual Basic Scripting Edition: With Statement, on MSDN
  7. GetRef Function, on MSDN
  8. Visual Basic Scripting Edition: SubMatches Collection, on MSDN
  9. What About VBScript?, within the article Introducing JScript .NET by Andrew Clinick of Microsoft Corporation, in Scripting Clinic on MSDN (July 14, 2000)
  10. "Deprecated features for Windows client". 7 November 2023.
  11. Introducing Windows Script Components, on MSDN
  12. "VBScript Features". msdn.microsoft.com. 24 October 2011.
  13. "How to stop an ActiveX control from running in Internet Explorer". Microsoft. 2007-08-24. Retrieved 2009-06-29.
  14. "Microsoft Security Advisory (960715): Update Rollup for ActiveX Kill Bits". Microsoft. 2009-01-17. Retrieved 2009-06-29.
  15. "VTool" script component – GUI and functional enhancements for WSH/VBS
  16. "VbsEdit - VBScript Editor with Debugger - VBS Editor". www.vbsedit.com.
  17. Corp., Spline Technologies. "SplineTech VBS Debugger, VBScript Debugger. Debug VBS". www.remotedebugger.com.
  18. Script Center, Microsoft web site targeting system administration scriptors
  19. "Quick Test Professional – Basics of VBScript". Archived from the original on 2010-02-17. Retrieved 2010-05-05.
  20. "Caché for Unstructured Data Analysis". InterSystems. Retrieved 2018-09-24.
  21. "Deprecated features in the Windows client - What's new in Windows". 7 November 2023.