VBScript (Microsoft Visual Basic Scripting Edition) is a deprecated programming language for scripting on Microsoft Windows using Component Object Model (COM), based on classic Visual Basic and Active Scripting. It was popular with system administrators for managing computers and automating many aspects of computing environments, and has been installed by default in every desktop release of Microsoft Windows since Windows 98; in Windows Server since Windows NT 4.0 Option Pack; and optionally with Windows CE (depending on the device it is installed on). VBScript running environments include Windows Script Host (WSH), Internet Explorer (IE), and Internet Information Services (IIS). The running environment is embeddable in other programs via the Microsoft Script Control (msscript.ocx). In October 2023, Microsoft announced that VBScript was deprecated. In May 2024, a multi-phase deprecation schedule was announced with disabling it by default "around 2027" and removing it sometime later.
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. On August 1, 1996, Internet Explorer was released with features that included VBScript. In version 5.0, the functionality of VBScript was increased with new features including regular expressions; classes; 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 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 decided to implement future support for VBScript within ASP.NET for web development, 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. After announcing plans to remove support for VBScript, Microsoft suggested migrating to PowerShell or JavaScript.
Environments
Client-side web In a web page loaded by Internet Explorer, VBScript is similar in function to JavaScript. The VBScript code in the HTML is logic that interacts with the Document Object Model (DOM) of the page – allowing for functionality not possible in HTML alone. However, other web browsers such as Chrome, Firefox and Opera do not support VBScript. Therefore, when client-side scripting and cross-browser compatibility are required, developers usually choose JavaScript due to its wide cross-browser compatibility.
Active server page VBScript is used for server-side web page functionality via Active Server Pages (ASP). The ASP engine, 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 displays the current time in 24-hour format.
Windows script host VBScript can run directly in the operating system via the Windows Script Host (WSH). A script file, usually with extension .vbs can be run either via Wscript.exe for graphical user interface (GUI) or Cscript.exe for command line interface (CLI).
Windows script file A Windows Script File (WSF), styled after XML, can include multiple VBS files and is therefore a library of VBScript code that can be reused in a modular way. The files have extension .wsf and can be executed using wscript.exe or cscript.exe, as with a .vbs file.
HTML Application 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.
Windows Script Component VBScript can also be used in a Windows Script Component, an ActiveX-enabled script class that can be invoked by other COM-enabled applications. These files have extension .wsc.
Functionality
Language features The VBScript language is modeled on classic Visual Basic. Notable features include: 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:
… excerpt ends here. Continue reading the full article.
