VBScript (short for Microsoft Visual Basic Scripting Edition , created by Microsoft ) is a subset of Visual Basic used as a general purpose script language . It is often compared to JScript .
VBScript can work in many environments, including:
- Windows Scripting Host (WSH): This is a scripting interpreter for Microsoft Windows systems, allowing you to write scripts to, for example, facilitate their administration.
- Microsoft Internet Information Services (IIS): This is the Microsoft web server. VBScript is the preferred language for Active Server Pages (ASP) programming, that is, writing server-side dynamic web pages.
VBScript is often used as a replacement for DOS batch files .
It does not work on Explorer versions for Mac OS .
Like any scripting language, VBScript is an interpreted language. It does not require compilation before it is run. On the other hand, it requires that the machine intended to run them has an interpreter, a program capable of understanding all the instructions present in the program. According to the use the different “interpreters” are:
- ASP ( asp.dll ) in a Web environment
- Wscript.exe in a Windows environment
- Cscript.exe in a command-line environment
- Mshta.exe for HTML applications .
VBScript files for Windows Scripting Host usually have the file extension
Other extensions exist and allow the execution of VBScript such as:
- VBE : VBScript encoded (not editable).
- WSF : can contain different languages at the same time (for example VBScript and JScript), XML tags indicate the language of each source.
- WSC : Windows Script Components source file.
Example program (to put in a file ‘bonjour.vbs’):
MsgBox "Hello World!"
Second example program, this one will chain two boxes of message:
Msgbox "Hello sir!" Msgbox "How are you?"
If Windows Scripting Host is successfully installed and enabled, the program will run by double-clicking its icon.
VBScript is also implemented in Microsoft Outlook as a scripting language used to respond to events in Outlook forms.
Some common examples of VBScript applications are the Microsoft Agent technology and the Windows Update service . Since these two examples also use ActiveX technology , it is mandatory to use Internet Explorer to see Web pages using VBScript.
Internet script language
- Dim declares a variable
- if if (condition)
- Then when (you enter an action)
- else if (new condition)
- End if (end of condition)
- Do while (loop (do as … executed at least once))
- While … wend (loop (do until …))
- For … next (loop (do until …))
- Do … loop ( infinite loop)
- & ( Concatenates strings)
- Inputbox (…) input box)
- Msgbox ( dialog box)
- Cint (…) ( calculates a number)
- Copyfile ( copy a file)
- Deletefile ( deletes a file)
- Fileexists ( search if a file exists)
The creation of a VBScript script, in a standard Windows environment, does not require the installation of special software:
- Launch a text editor ( notepad / notepad type )
- Copy the script instructions (below)
- Save the file with a ‘.vbs’ extension.
- Open the file to run the script
For example a small script to give the time:
Time = "It is" & Hour ( Now ) & "h &" & Minute ( Now ) & "min." If Hour ( Now ) <= 18 then Message = "Hello" else Message = "Good evening" end if MsgBox Message & "!" & Vbnewline & Time
Another VBscript that gives the time, with inclusion of the inputbox:
firstname = inputbox ( firstname , "What is your name?" ) Time = "is" & Hour ( Now ) & "h" & Minute ( Now ) & "min and" & Second ( Now ) & "dry." If Hour ( Now ) <= 18 then Message = "Hello" else Message = "Good evening" End if if Hour ( Now ) <= 18 then Message2 = "Spend a good day!" else Message2 = "Have a good night!" End if MsgBox Message & "" & prenom & "!" & Vbnewline & Time & vbnewline & Message2 else Message2 = "Have a good night!" End if MsgBox Message & "" & prenom & "!" & Vbnewline & Time & vbnewline & Message2 else Message2 = "Have a good night!" End if MsgBox Message & "" & prenom & "!" & Vbnewline & Time & vbnewline & Message2
Language and object
VBScript allows you to manipulate objects in Windows . It also creates classes in which members can be either private or public. However, inheritance does not exist in VBScript.
Computer viruses and VBScript
Allowing to perform virtually any operation under a Windows system using ActiveX technology , VBscript has been used for the creation of many computer viruses.
Many viruses written in VBscript appear in the year 2000. One of the best known is the virus “VBS.LoveLetter” also known as ” I love you “.
Simple text editors like Notepad are enough to develop in VBScript.
Nevertheless, there are many editors dedicated to VBScript like:
- VBS Factory
- Microsoft Script Editor ( scripting languages including VBScript)
- VbsEdit (contains an integrated debugger )
Tools allow scripting to be used without knowledge of development
- GlobalscriptGUI [ archive ]
Notes and references
- ↑ VBScript is not supported in IE11 edge mode [ archive ]