Visual Basic Script
Visual Basic Script (short: VBScript or VBS ) is a scripting language developed by Microsoft . It is closely related to Visual Basic (VB) and Visual Basic for Applications (VBA) and is commonly interpreted .
Areas of application
VBS can access all COM components with IDispatch interface that are available under Windows , in particular the libraries of Microsoft Office programs, databases such as Access and SQL Server , other applications and of course the libraries of the operating system. The use of normal program libraries (DLL files) is not intended and only possible with the appropriate COM support. In practice, there are three areas of application for VBS:
Windows operating system
The control of the Windows operating system for the automation of standard tasks is possible with your own scripts via the Windows Script Host (WSH). Windows mainly accepts VBS within
.WSFfiles executed by the Windows Scripting Host (since versions 2000 / ME) and within
Browser (client-side VBS)
Web server (server-side VBS)
For servers under Windows, VBS is an integral part of Microsoft's ASP ( Active Server Pages ). The VBS code is integrated into an HTML page with the file extension ASP. The Web Service Internet Information Services , interprets the ASP file as a program and returns the result to the client (for example, the browser a website visitor) from. In this way, for. B. a database is queried, the result of which is processed and output - usually as an HTML file.
ASP is thus in competition with concepts such as PHP . The Microsoft web server service IIS is comparable to the Apache web server . In the meantime, the concept described above is also referred to as "Classic ASP" in order to differentiate it from the successor products (see also the section on the outlook).
Future use of VBScript
VBScript is still supported by Microsoft as a system component of all current Windows versions. However, the language itself has not been further developed for a long time. Hence, it is sometimes viewed as "dead language". Microsoft also offers various successor products and favors their use; This can also be seen in the fact that Microsoft's WSH-related websites are disappearing. However, due to the comparatively high acceptance of the old products and the widespread use of solutions based on them, they will still spend a considerable amount of time in coexistence.
- In the area of web servers, ASP.NET should take over the tasks of the so-called "Classic ASP", and the programming language Visual Basic .NET should replace VBS.
- Windows PowerShell now exists to support administrative tasks , so it can be used as a successor product to Windows Script Host.
- The free Visual Studio Express editions are also available for the implementation of extensive and complex programs .
The main advantages of the language are:
- available on all Windows operating systems from 2000 / 98SE (with IE 4 also from Windows 95);
- small file sizes as the language is interpreted by the operating system or browser;
- Previous knowledge of the languages Visual Basic (VB) and VBA make it easier to get started with VBS;
- Access to other applications and installed components (for example Microsoft Office programs) and their object model ;
- Expandability through specially developed components (objects).
The disadvantages include:
- no development environment (IDE) to support larger projects; The Script Debugger and Script Editor programs offered by Microsoft should rather be viewed as stopgaps;
- no use outside of Microsoft products;
- Incompatibility with other operating systems.
- Compared to Visual Basic (VB) and Visual Basic for Applications (VBA), VBS has no data typing, there is only the Variant data type , which can save all other types.
- The range of functions is further reduced compared to VB.
- Classes can be created.
- As with most scripting languages, the VBScript programs (scripts) are available as source text. It is therefore hardly possible to protect your own code from being viewed. The incidental display of the source code can be prevented by a simple type of encryption, either using an MS Script Encoder or an ActiveX control element ("Scripting.Encoder" object). Encrypted VBScript files have the extension
A simple VBScript for displaying a dialog window could look like this:
MsgBox "Textinhalt des Fensters", 0, "Name des Fensters"
The second argument determines the appearance of the window. The value
0corresponds to a simple window that displays an OK button next to the text content , but there are other design options such as various buttons or symbols.
If, for example, this code is saved in a text file with the extension using the editor included in Windows
.vbs, a double click is sufficient to execute it.
As a component of Internet Explorer, VBScript - like other active content - can pose an additional security risk if appropriately prepared websites can exploit an existing security gap. Such gaps were closed with Microsoft's updates from June 2020, for example. The risks can be avoided by preventing script execution in Internet Explorer or by using a different browser.
After Microsoft decided to also allow VBScript as part of HTML mails within Microsoft Outlook and Outlook Express , numerous viruses have spread through these applications using the initially insufficiently protected interface to ActiveX control elements. The potential danger here is not the special properties of VBScript, but the close connection of scripts with other system components. A similar risk is associated with PowerShell scripts, for example.
Since scripts are available as text files, their program character is sometimes overlooked. This can lead to underestimating their potential impact. The “Open” command does not load a script for editing either, but rather executes it.
- MSDN Scripting : Microsoft's current overview page for Windows Script (mostly obsolete links when accessed on February 21 and March 4, 2019)
- Script Center (Script resources) : Script Center Site with various downloads
- Microsoft Scripting Blog : Tips and Examples
- dieyer.de : Informative page on the use of VBS with many examples and explanations
- ArsTechnica.de : Examples for automation with VB scripts
- HTMLWorld : Introduction to VBScript
- Macro Center : Code snippets for VBScript
- Script component VTool : Function extensions and various dialog windows for WSH / VBS (freeware)
- MSDN forum: Accessing Win32 API in VBScript files - DLL function call using Excel macro
- Script component (freeware): WSH / VBS function extension DynaLib - DLL function call via COM object
- heise online: Browser cuts off old braids: IE 11 in future without activated VBScript. Retrieved August 4, 2019 .
- Download MS Script Encoder (via archive) ( Memento from July 18, 2012 in the Internet Archive )
- Microsoft Update Information: Security Update Guide, June 2020 Security Updates. Retrieved June 10, 2020 .