VBScript(MicrosoftVisual BasicScripting Edition) is adeprecatedprogramming languageforscriptingonMicrosoft WindowsusingComponent Object Model(COM) based onclassic Visual BasicandActive Scripting.

VBScript
DeveloperMicrosoft
First appeared1996;28 years ago(1996)
Stable release
5.8
OSWindows
Filename extensions.vbs,.vbe,.wsf,.wsc(.asp,.hta,.htm,.html)
Websitehttps://learn.microsoft.com/previous-versions/t0aew7h6(v=vs.85)
Majorimplementations
Windows Script Host,Active Server Pages
Influenced by
Visual Basic
Influenced
Windows PowerShell

VBScript was popular withsystem administratorsfor managingcomputers;automating many aspects of computing environment.

VBScript running environments include:Windows Script Host(WSH),Internet Explorer(IE), andInternet Information Services(IIS).[1]The running environment is embeddable in other programs via the Microsoft Script Control (msscript.ocx).

VBScript has been installed by default in every desktop release ofMicrosoft WindowssinceWindows 98;[2]inWindows ServersinceWindows NT 4.0 Option Pack;[3]and optionally withWindows CE(depending on the device it is installed on).

In October 2023, Microsoft announced that VBScript was deprecated.[4]In May 2024, a multi-phase deprecation schedule was announced with removal planned for 2027 or later.[5]

History

edit

VBScript began as part of the Microsoft Windows Script Technologies, launched in 1996. This technology (which also includedJScript) 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 Windowssystem administratorsseeking an automation tool more powerful than thebatch languagefirst developed in the early 1980s.[6]On August 1, 1996,Internet Explorerwas released with features that included VBScript.[7]

In version 5.0, the functionality of VBScript was increased with new features includingregular expressions;classes;theWithstatement;[8]theEval,Execute,andExecuteGlobalfunctions to evaluate and execute script commands built during the execution of another script; a function-pointer system via GetRef,[9]andDistributed COM(DCOM) support.

In version 5.5,SubMatches[10]were added to theregular expressionclass 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 withinASP.NETfor web development,[11]and therefore no new versions of the VBScript engine would be developed. It would henceforth be supported by Microsoft'sSustaining Engineering Team,who are responsible for bug fixes and security enhancements. For Windows system administrators, Microsoft suggests migrating toWindows PowerShell,as VBScript is deprecated and will eventually be removed from Windows.

Environments

edit

Client-side web

edit

In a web page loaded byInternet Explorer,VBScript is similar in function toJavaScript.The VBScript code in the HTML is logic that interacts with theDocument Object Model(DOM) of the page – allowing for functionality not possible in HTML alone. However, other web browsers such asChrome,FirefoxandOperado 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

edit

VBScript is used for server-side web page functionality viaActive Server Pages(ASP). The ASP engine,asp.dll,invokesvbscript.dllto 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.

<%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>

Windows script host

edit

VBScript can run directly in the operating system via theWindows Script Host(WSH). A script file, usually withextension.vbscan be run either viaWscript.exeforgraphical user interface(GUI) orCscript.exeforcommand line interface(CLI).

Windows script file

edit

AWindows 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.wsfand can be executed usingwscript.exeorcscript.exe,as with a.vbsfile.

HTML Application

edit

AnHTML 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.htaand can be executed usingmshta.exe.

Windows Script Component

edit

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

Functionality

edit

Language features

edit

The VBScript language is modeled on classic Visual Basic.[13]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 functionsMsgBoxandInputBoxwhich 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 anHTML Application.Event-driven forms are not supported as in Visual Basic orVisual 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

edit

When hosted by theWindows Script Host,VBScript provides numerous features which are common to scripting languages, but not available fromVisual Basic 6.0.These features include:

  • Named and unnamed command line arguments
  • Stdinandstdout,which could be redirected
  • WSH.Echo which writes to the console and cannot be redirected
  • WSH.ExitCode which can be tested from DOS batch files, or by the process which invoked the script file
  • Network printers
  • Network shares
  • Special folders, e.g. Desktop, Favorites, MyDocuments and so on
  • Network user information, such as group membership
  • Methods for runtime execution of text defined at runtime: Eval and Execute
  • Methods for executing scripts on remote machines
  • Windows Management Instrumentation(WMI)
  • Functionality for embedding a VBScript engine in other applications, using a widely known language

CScript, the command line runner, provides options for:

  • Interactive or batch mode
  • Invoking debug mode from the command line
  • Error reporting including the line number

Additional functionality

edit

File system management, file modification, and streaming text operations are implemented with the Scripting Runtime Libraryscrrun.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 throughActiveX Data Objects(ADO), and theIIS Metabasecan 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 theMicrosoft XML LibraryApplication 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 thekillbitvia monthly Windows security updates to disable vulnerable Microsoft and third party code.[14][15]

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.[16]

Development tools

edit

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

For debugging purposes theMicrosoft Script Debuggercan 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,[17][18]and manytext editorsoffersyntax highlightingfor 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

edit

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,[19]but it has since been vastly surpassed byPowerShell.Second, VBScript is the scripting language forMicro Focus Unified Functional Testing,a test automation tool.[20]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 DBMSInterSystemsCaché(which has its roots in the languageMUMPS) also supports an implementation of VBScript, Cache BASIC, for programming stored code.[21]

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 licensesVisual 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 ADODBActiveX Data Objects(ADODB) for effective database connectivity.

VBScript can also be used to createmalwareand viruses, such as theILOVEYOUworm that spread through email attachment in Outlook 97 that cost billions of dollars.

See also

edit

References

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