Introduction

VBScript or VBS is a Microsoft interpreted script version of the Visual Basic programming language, it uses most of its grammar but has some limited resources compared, like some VB keywords doesn't work. It can be used on ASP, HTA and mainly as standalone scripts, executed by Windows Script Host (WSH) or CScript to do automated tasks on Microsoft Windows Operating Systems. It can use COM to access some Windows more advanced resources like Network, Databases, System data, Registry, Schedule, Printing, Active Directory and some other resources. VBScript came first by default on Windows 98 and it is being shipped in every Windows OS since then. However, Microsoft wants to make it a optional add-on from Windows 11 onwards. Today it is on its version 5.8 and was created by Alan Cooper. It is a more advanced and more useful language compared to Batch Script, but it is outdated since PowerShell was released as a more advanced language for Windows Admins and Hackers. You can identify a VBS file by its suffix in the end of the files names, like: example.vbs or as an encrypted version, like: example.vbe. The main advantages to use VBS are:

  • considered an easy to learn & use programming language
  • can use to open programs and send keypresses including control/shift/alt keys
  • can be used as a quick test automation tool
  • lightweight and fast interpreted
  • can easily make automation scripts for Windows OS
  • updated compared to CMD
  • shipped with every Windows until its 11th version
  • faster to learn, easier and simpler than PowerShell

And the disadvantages:
  • outdated compared to Powershell
  • does not fully support OOP
  • few support from Microsoft, community an lacks of tools
  • can't access Win32 API, even less .NET framework, can only COM/DCOM interfacing
  • sometimes it is hard to debug what exactly is wrong
  • does not receives more updates since some years ago

Your first "hello world"

On Windows, create a file where you want, and put this code inside:
MsgBox "Hello, World!"
and save the file with the name hello.vbs, your file should change its icon to this:

VBScript file icon

now you can double click the file and it should execute showing the message box! Congrats, you made your first "Hello World" in VBS.

Comments

There are 3 ways to implement comments in VBS

By single quote: ' this is a single line comment

By using the REM keyword: REM this is a single line comment

Variables

You can create empty variables using the DIM keyword:

Dim var1 Dim var2, var3 ' You can add multiple var declarations separated by comma

or you can define it directly without using the DIM keyword:

name = "John" age = 19
Data types

VBScript has only one data type called "Variant" with many subtypes, let's see:

SubType | VarType() Represented by Const Const Value Description
Empty vbEmpty 0 Empty, uninitialized
Null vbNull 1 Null, no valid data
Integer vbInteger 2 integer in the range -32,768 to 32,767
Long vbLong 3 Long Integer in the range -2,147,483,648 to 2,147,483,647
Single vbSingle 4 Single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values
Double vbDouble 5 Double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values
Currency vbCurrency 6 -922,337,203,685,477.5808 to 922,337,203,685,477.5807
Date vbDate 7 Number that represents a date between January 1, 100 to December 31, 9999
String vbString 8 String that can be up to approximately 2 billion characters in length
Object vbObject 9 Automation object
Error vbError 10 Contains an error number
Boolean vbBoolean 11 Either True or False
Variant vbVariant 12 Variant (used only with arrays of Variants)
DataObject vbDataObject 13 A data-access object
Decimal vbDecimal 14 Decimal Value
Byte vbByte 17 Contains only a byte
LongLong vbLongLong 20 LongLong integer (64 bit)
Array vbArray 8192 Array
Constants

Constants, or just consts, are a language syntax to define values assigned once, that will never vary later, for example: Const Pi = 3.14159265358979 Const MicrosoftFounder = "Bill Gates"

WIP - to be continued