VBScript


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 .

Usage Environments

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.
  • Windows Internet Explorer : The VBScript language can be integrated into HTML pages, just like Javascript to offer interactive features.
  • 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 .

Interpreted language

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 .vbs .

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.

The version of VBScript implemented in Internet Explorer contains functions very similar to those of JavaScript ; It has an interpreter that processes code embedded in HTML , and can not create independent applications. It has virtually no compatibility with other browsers, so virtually all webmasters are currently dropping VBScript in favor of JavaScript . It does not work for example with any of the browsers offered on Mac.

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

VBScript is a Microsoft language and is only interpreted by Internet Explorer. Therefore this language does not have the portability of JavaScript for example. VBScript was implemented for the first time in Internet Explorer in version 3 of the browser, but the lack of interoperability with Netscape / Mozilla / Opera implies that, whenever possible, JavaScript is preferred. It is dropped in IE11 and in Edge , the new browser of Microsoft 1 .

Keywords

  • 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)
  • Mod
  • & ( 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)

Syntax

The creation of a VBScript script, in a standard Windows environment, does not require the installation of special software:

  1. Launch a text editor ( notepad / notepad type )
  2. Copy the script instructions (below)
  3. Save the file with a ‘.vbs’ extension.
  4. 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 “.

Editors

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

  1. ↑ VBScript is not supported in IE11 edge mode  [ archive ]