Lecture 1

Scripting Concepts

Welcome to the very first online lecture of this exciting subject. I am sure that you feel more relaxed to have a lecture at home than having in the campus. Take easy, and make yourself a cup of coffee - no sugar please:)



The lecture notes have been kept in short and interesting, so you won't feel them boring.


Key words


WSH (Windows Script Host), VBScript (short for Visual Basic Scripting Edition).


Reference to textbook chapters


This lecture covers the first two chapters of the textbook (Don Jones, VBScript, WMI and ADSI unleashed : using VBSscript, WMI, and ADSI to automate Windows administration eBook: Chapter 1. Scripting Concepts and Terminology and Chapter 2. Running Scripts).



"What! You want us to read the textbook?"


Well, if you strictly follow me to work on the material provided here and play with the sample scripts, you may not need to. Otherwise, you have to. Anyway, the book is very well written and a reference to the text is certainly helpful for an in-depth understanding.


Let's start to play


Download the script: Sample1.vbs. Save it in any folder and double click it. By the way, you have to work with Windows (hopefully the version is no earlier than Windows 2000).


You will see "I am Jamie Yang!" in a small window. Otherwise, you might have to reinstall your operating system. Of course, you are not 'Jamie Yang'. Right click the file and choose Edit. You will open it in Notepad. Change 'Jamie Yang' to your name. Run it again - does it display your name?


If succeeded, try on another one: Sample2.vbs.


What do we mean by scripting?


"For the purposes of this book, scripting refers to the act of creating, executing, and utilizing small computer programs that are written in a high-end scripting language, specifically, VBScript."


Not really. VBScript is just one of the many scripting languages. There are plenty of others, some for unix, some for Windows, and some for both. Examples of scripting languages are Perl, php, shell script, JScript, JavaScript, .... In this subject, we will use VBScript for Windows and Perl for Unix.


By the way, is there any link between VBScript and Visual Basic, also JavaScript and Java? Yes, there is. VBScript can be viewed as a lightweight version of VB and JavaScript can be viewed as a lightweight version of Java. If you do not agree, think in this way - they are similar in syntax at least. However, unlike C and C++, none of the pairs is compatible.


What about JavaScript and JScript? JScript is Windows' version of JavaScript. It is more C style.


VB is one of the simplest programming languages, compared to Java, C, and C++. VBScript is even simpler. Therefore we are learning probably the simplest programming language in the world.


Common characteristics of scripting languages:

  1. 1. Interpreted: the scripting engine reads each line of script, one at a time, and executes it.

  2. 2. Text-based: program itself is a text file.

  3. 3. Native: mostly a scripting language can only be used for certain purposes or with certain operating systems.

  4. 4. Easy to deploy: lightweight.


The environment running VBScript programs


Like VB and Java, VBScript is an interpreted language, which means that the program itself is not runnable. It needs another program to execute it. This program is Windows Script Host (WSH). The WSH architecture is shown in the figure below:



WSH is a built-in component of Windows 2000, Windows XP, Windows Server 2003, Windows Vista, and later versions of Windows. If you have an early version of Windows, you need to download a file WScript.exe or CScript.exe from Microsoft.


WScript.exe is window-based WSH environment, and CScript.exe sets up a command-line style of WSH interpreter. Try this:

  1. 1.Open a command-line window.

  2. 2.Change directory to the folder where the script sample1.vbs is.

  3. 3.Enter: CScript sample1.vbs.


You will see the same message appears in the command-line window as you have seen by double clicking the program. Trust me. CScript.exe is useful when you debug a program.


We can do more things using VBScript


VBScript is completely capable of utilizing COM, the Component Object Model, which makes VBScript powerful. You can get a COM object by using the function: GetObject(). As such you can use almost all Windows' functionalities as well as other Microsoft applications' functionalities packaged in COM. Try this:


Download the script, SerialNoOS.vbs, and execute it.


This script tells you the serial number of your Windows operating system. Of course, you need a good knowledge of Windows systems to know where the information is stored. At least, you now know where it is. So try more, know more. Here is another one.


Download the script, WhoOpened.vbs, and execute it.


The language itself isn't complicated, is it? However, to do a better job, we need to use some appropriate functionalities/services of the operating system. How to locate the relevant functionalities for carrying out a task? This could be the scary point of learning VBScript. A good thing is that you don't have to know everything about the operating system. Most administrative tasks are quite routine. You only need to know a few facts. Then you use them every day. Or once a job is done, it works forever. This is what we want to achieve with this subject.


I have to remind you that the power of VBScript can be used not only for beneficial administrative tasks, but also for malicious hacking, and many viruses are based on VBScript or other AcvtiveX scripting languages.


That's all for today. Now have a cup of tea?