Let's talk about VBscript


VBScript is a scripting language derived from Visual Basic. It is an interpreted language. This means that, unlike compiled languages where information is reconstructed into machine language before being executable, command pass through an interpreter that takes care of translating them into machine language line by line at the time of their execution.

VBScript is a scripting language derived from Visual Basic. It is an interpreted language. This means that, unlike compiled languages where information is reconstructed into machine language before being executable, command pass through an interpreter that takes care of translating them into machine language line by line at the time of their execution.

A script is a text file that contains commands that are executed sequence by the command interpreter. The language used is called an interpreted language as opposed to compiled languages, because it is executed without further processing. Compiled (like C language) language is also written in text format, but it is in an unusable state. It must first undergo a treatment (compilation) that will allow it to run. This code is transformed into executable file (file extension. Exe).
The advantage of the compiled program is that it can be used alone, without interpreter.

Generally, compiled programs are faster and more efficient because the commands are processed at compile time in a language directly understandable by the machine and will no longer need to go through an intermediary interpreter at run time. The advantage of an interpreted language is its simplicity of use, the controls are generally much simpler than a compiled language, at the cost of some concessions:

• reduced speed ;
• Lack of flexibility in the arrangement of the code as soon as it takes some significant momentum.

Presentation of a VBS script



A VBS script is a text file editable through Notepad program or a script editor in text mode.
Consider a simple example script, the famous Hello World! :
wscript.echo "Hello World!"
Save this file with the extension. Vbs (hello.vbs for example) and run it by double-clicking on it, you just made your first program, your first script. Another example is a little more oriented system: The script below allows mapping, that is to say, to associate a network drive J: pointing to the share \ data
Set objetNetwork= CreateObject ("WScript.Network")
objetNetwork.MapNetworkDrive "J:", "\ \ myserver \ Data"
Just save this script as file.vbs to make it a script. It can be used on all Windows systems with VBS script interpreter.


What is happening when the script is executed?



Extension Files .Vbs are associated by default to WSH script interpreter named wscript.exe. If you double click the file, the system runs: wscript yourscript.vbs
wscript will go through the script (looking for errors) and then translate commands for the system. Remember that VBScript is an interpreted language that will serve as a basis for call to the functionality of other technologies.

Windows Script Host: Interpreter, and more if affinity



Windows Script Host (WSH) is a scripting host. More simply, it is the program that will interpret and execute each command line of your script. WSH was developed by Microsoft as a multi-language interpreter. Thus, if it is able to interpret written files in VBScript , it is also able to include scripts written in other languages like Javascript or Active Perl.
WSH offers more than just an interpreter. Already WSH offers not one but two interpreters for your scripts:
• Wscript, as we have seen, is an interpreter in windowed mode ( Wscript
for Windows Script) is the mode by default of WSH.
• Cscript is another interpreter console mode this time ( Cscript for
Script console).

What is the difference between windowed mode and console mode?



The difference between these two modes lies in the way which is managed waht we called the standard output . Standard output is the channel through which will express your script. With Wscript, standard output is directed into the GUI in dialog boxes (Message Box) of the graphical environment. Once your script has something to say, he will do it through a dialog box. With Cscript, the output is redirected to the console in text mode.
WSH is not just a command interpreter.WSH also provides an integrated set of objects that can be used in your VBS scripts. But ....

What is an object?



An object is a component developed by programmers, accessible in your scripts and providing two types of features:
• Methods: These are actions the object can perform for you;
• properties: it is information that may return to you.

VBScript and WSH script host language have embedded objects. these objects are said to be integrated because it can be accessed directly without having to create an instance.
We will clarify this point. Foremost, to use an object (not integrated), we must create an instance.
Set objetNetwork= CreateObject("Wscript.Network")
objetNetwork.MapNetworkDrive "J:", "\totoData"

What have we here?



In the first line, we created what we call an instance of the object WScript.Network. We have called the object to be able to enjoy of its features. We can say that we invoked an object to provide us with its methods and attributes. We have instantiated an object (we will see in detail what all that means). This item is part of those offered natively by WSH.
In the second line, we use the MapNetworkDrive method that allows us to create network maps. As you can see, the name of our instantiated object is used (here objetNetwork is a name that is chosen arbitrarily) attached to the selected method:

objetNetwork.MapNetworkDrive


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: