VBScript
   HOME

TheInfoList



OR:

VBScript (''"
Microsoft Microsoft Corporation is an American multinational technology corporation producing computer software, consumer electronics, personal computers, and related services headquartered at the Microsoft Redmond campus located in Redmond, Washing ...
Visual Basic Visual Basic is a name for a family of programming languages from Microsoft. It may refer to: * Visual Basic .NET (now simply referred to as "Visual Basic"), the current version of Visual Basic launched in 2002 which runs on .NET * Visual Basic (cl ...
Scripting Edition"'') is an
Active Scripting Active Scripting (formerly known as ActiveX Scripting) is the technology used in Windows to implement component-based scripting support. It is based on OLE Automation (part of COM) and allows installation of additional scripting engines in the form ...
language developed by Microsoft that is modeled on
Visual Basic Visual Basic is a name for a family of programming languages from Microsoft. It may refer to: * Visual Basic .NET (now simply referred to as "Visual Basic"), the current version of Visual Basic launched in 2002 which runs on .NET * Visual Basic (cl ...
. It allows
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
system administrator A system administrator, or sysadmin, or admin is a person who is responsible for the upkeep, configuration, and reliable operation of computer systems, especially multi-user computers, such as servers. The system administrator seeks to en ...
s to generate powerful tools for managing computers without
error handling In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
and with
subroutine In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed. Functions may ...
s and other advanced programming constructs. It can give the user complete control over many aspects of their computing environment. 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 In computer programming, create, read, update, and delete (CRUD) are the four basic operations of persistent storage. CRUD is also sometimes used to describe user interface conventions that facilitate viewing, searching, and changing information u ...
files. VBScript has been installed by default in every desktop release of
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
since
Windows 98 Windows 98 is a consumer-oriented operating system developed by Microsoft as part of its Windows 9x family of Microsoft Windows operating systems. The second operating system in the 9x line, it is the successor to Windows 95, and was released to ...
; in
Windows Server Windows Server (formerly Windows NT Server) is a group of operating systems (OS) for servers that Microsoft has been developing since July 27, 1993. The first OS that was released for this platform was Windows NT 3.1 Advanced Server. With the r ...
since Windows NT 4.0 Option Pack; and optionally with
Windows CE Windows Embedded Compact, formerly Windows Embedded CE, Windows Powered and Windows CE, is an operating system subfamily developed by Microsoft as part of its Windows Embedded family of products. Unlike Windows Embedded Standard, which is base ...
(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 The Microsoft Windows Script Host (WSH) (formerly named Windows Scripting Host) is an automation technology for Microsoft Windows operating systems that provides scripting abilities comparable to batch files, but with a wider range of supported fe ...
(WSH),
Internet Explorer Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated IE or MSIE) is a series of graphical user interface, graphical web browsers developed by Microsoft which was used in the Microsoft Wind ...
(IE), and
Internet Information Services Internet Information Services (IIS-pronounced 2S, formerly Internet Information Server) is an extensible web server software created by Microsoft for use with the Windows NT family. IIS supports HTTP, HTTP/2, HTTPS, FTP, FTPS, SMTP and NN ...
(IIS). Additionally, the VBScript hosting environment is embeddable in other programs, through technologies such as the Microsoft Script Control ().


History

VBScript began as part of the Microsoft Windows Script Technologies, launched in 1996. This technology (which also included
JScript JScript is Microsoft's legacy dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer 11 and older. JScript is implemented as an Active Scripting engine. This means that it can be "plugged in" to OLE Automation applicati ...
) 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 administrator A system administrator, or sysadmin, or admin is a person who is responsible for the upkeep, configuration, and reliable operation of computer systems, especially multi-user computers, such as servers. The system administrator seeks to en ...
s seeking an automation tool more powerful than the batch language first developed in the early 1980s. On August 1, 1996,
Internet Explorer Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated IE or MSIE) is a series of graphical user interface, graphical web browsers developed by Microsoft which was used in the Microsoft Wind ...
was released with features that included VBScript. In version 5.0, the functionality of VBScript was increased with new features including
regular expression A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or ...
s; 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 .NET Framework (pronounced as "''dot net"'') is a proprietary software framework developed by Microsoft that runs primarily on Microsoft Windows. It was the predominant implementation of the Common Language Infrastructure (CLI) until bein ...
, the scripting team took the decision to implement future support for VBScript within
ASP.NET ASP.NET is an open-source, server-side web-application framework designed for web development to produce dynamic web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, applications and services. The name s ...
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. For Windows system administrators, Microsoft suggests migrating to
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-so ...
. However, the scripting engine will continue to be shipped with future releases of Microsoft Windows and IIS.


Environments

When employed for client-side web development in Microsoft
Internet Explorer Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated IE or MSIE) is a series of graphical user interface, graphical web browsers developed by Microsoft which was used in the Microsoft Wind ...
, VBScript is similar in function to
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
. It is used to write executable functions that are embedded in or included from HTML pages and interact with the
Document Object Model The Document Object Model (DOM) is a cross-platform and language-independent interface that treats an XML or HTML document as a tree structure wherein each node is an object representing a part of the document. The DOM represents a document wi ...
(DOM) of the page, to perform tasks not possible in HTML alone. However, other web browsers such as
Firefox Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements current and ...
and
Opera Opera is a form of theatre in which music is a fundamental component and dramatic roles are taken by singers. Such a "work" (the literal translation of the Italian word "opera") is typically a collaboration between a composer and a librett ...
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 Active Server Pages (ASP) is Microsoft's first server-side scripting language and engine for dynamic web pages. It was first released in December 1996, before being superseded in January 2002 by ASP.NET. History Initially released as an add ...
(ASP). The ASP engine and type library, , invokes 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. <% Option Explicit %> VBScript Example
<% ' 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. 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 workstation running
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
. The simplest example is a script that makes use of the
Windows Script Host The Microsoft Windows Script Host (WSH) (formerly named Windows Scripting Host) is an automation technology for Microsoft Windows operating systems that provides scripting abilities comparable to batch files, but with a wider range of supported fe ...
(WSH) environment. Such a script is usually in a stand-alone file with the
file extension A filename extension, file name extension or file extension is a suffix to the name of a computer file (e.g., .txt, .docx, .md). The extension indicates a characteristic of the file contents or its intended use. A filename extension is typically d ...
.vbs. The script can be invoked in two ways: is used to display output and receive input through a GUI, such as dialog and input boxes. is used in a command line environment. VBScript can be included in two other types of scripting files:
Windows Script File 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 ...
s, and
HTML Application 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 us ...
s. 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 or , 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 . and can be executed using . 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. These files have extension . 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. 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 Variant may refer to: In arts and entertainment * ''Variant'' (magazine), a former British cultural magazine * Variant cover, an issue of comic books with varying cover art * ''Variant'' (novel), a novel by Robison Wells * " The Variant", 2021 e ...
" 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 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 us ...
. Event-driven forms are not supported as in Visual Basic or
Visual Basic for Applications 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 support ...
. 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 The Microsoft Windows Script Host (WSH) (formerly named Windows Scripting Host) is an automation technology for Microsoft Windows operating systems that provides scripting abilities comparable to batch files, but with a wider range of supported fe ...
, VBScript provides numerous features which are common to scripting languages, but not available from
Visual Basic 6.0 The original Visual Basic (also referred to as Classic Visual Basic) is a third-generation programming language, third-generation event-driven programming, event-driven programming language from Microsoft known for its Component Object Model ( ...
. These features include direct or easy access to: * Named and unnamed command line arguments, *
Stdin In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin ...
and
stdout In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin ...
, 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

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 In computing, Microsoft's ActiveX Data Objects (ADO) comprises a set of Component Object Model (COM) objects for accessing data sources. A part of MDAC (Microsoft Data Access Components), it provides a middleware layer between programming lan ...
(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 Interface An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how t ...
s (, ), 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 Killbit is a security feature in web browsers based on Microsoft's Trident engine (such as Internet Explorer) and other ActiveX containers that respect the killbit (such as Microsoft Office). A killbit instructs an ActiveX control container neve ...
via monthly Windows security updates to disable vulnerable Microsoft and third party code. 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.


Development tools

Microsoft does not routinely make available an IDE (
Integrated Development Environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools a ...
) for VBScript, although the
Microsoft Script Editor The Microsoft Script Editor (MSE or "MSE.EXE" or "mse7.exe" in Office 2003) is an optional tool included in Microsoft Office 2000 through Office 2007 and is found in "%ProgramFiles%\Microsoft Office\OFFICE11" directory for Office 2003 (under 32-b ...
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, and many
text editors A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be u ...
offer
syntax highlighting Syntax highlighting is a feature of text editors that are used for programming, scripting, or markup languages, such as HTML. The feature displays text, especially source code, in different colours and fonts according to the category of terms ...
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., but it has since been vastly surpassed by
PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell (computing), shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it ...
. Second, VBScript is the scripting language for Micro Focus Unified Functional Testing, a test automation tool. 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 InterSystems Corporation is a privately held vendor of software systems and technology for high-performance database management, rapid application development, integration, and healthcare information systems. The vendor's products includInter ...
Caché (which has its roots in the language MUMPS) also supports an implementation of VBScript, Cache BASIC, for programming stored code. 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. When an organization licenses
Visual Basic for Applications 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 support ...
(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 In computing, Microsoft's ActiveX Data Objects (ADO) comprises a set of Component Object Model (COM) objects for accessing data sources. A part of MDAC (Microsoft Data Access Components), it provides a middleware layer between programming lan ...
(ADODB) for effective database connectivity. VBScript can also be used to create
malware Malware (a portmanteau for ''malicious software'') is any software intentionally designed to cause disruption to a computer, server, client, or computer network, leak private information, gain unauthorized access to information or systems, depri ...
and viruses, such as the
ILOVEYOU ILOVEYOU, sometimes referred to as Love Bug or Love Letter for you, is a computer worm that infected over ten million Windows personal computers on and after 5 May 2000. It started spreading as an email message with the subject line "ILOVEYOU" ...
worm that spread through email attachment in Outlook 97 that cost billions of dollars.


See also

*
AppleScript AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system aut ...
*
FastTrack Scripting Host FastTrack Automation Studio (formerly known as FastTrack Scripting Host), often referred to as just FastTrack, is a scripting language for Windows IT System Administrators. The product’s goal is to handle any kind of scripting that might be requ ...
*
HTML Components HTML Components (HTCs) are a legacy technology used to implement components in script as Dynamic HTML (DHTML) "behaviors" in the Microsoft Internet Explorer web browser. Such files typically use an .htc extension and the "text/x-component" MIME ty ...
*
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
* JScript .NET *
JScript JScript is Microsoft's legacy dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer 11 and older. JScript is implemented as an Active Scripting engine. This means that it can be "plugged in" to OLE Automation applicati ...
*
PerlScript ActivePerl is a distribution of Perl from ActiveState (formerly part of Sophos) for Windows, macOS, Linux, Solaris, AIX and HP-UX. A few main editions are available, including: Community (free, for development use only), and several paid tier ...
*
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-so ...
*
Windows Script File 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 ...


References


External links


VBScript Language Reference
Microsoft Docs
Is VBScript Dead?
isvbscriptdead.com
VBScript Commands
ss64.com

ss64.com
WMI Overview
Microsoft TechNet {{Authority control BASIC programming language family Internet Explorer Microsoft programming languages Programming languages created in 1996 Scripting languages Windows components