Topics: Batch file, Subroutine, Windows Script Host Pages: 7 (2069 words) Published: February 8, 2014
VBScript Modular Programming Lab

In this lab, students will complete the following objectives. Create a VBScript program using NotePad++.
Use procedures to modularize a VBScript program.
Create a library of procedures.
Run library procedures from a separate VBScript program.

Element K Network Connections

For this lab, we will only need to connect to vlab-PC1. The computer vlab-PC1 is the computer on the left side while vlab-PC2 is on the right. If you leave the cursor on the PC icon for a few seconds, a tool-tip message will appear indicating the hostname of the PC. Open vlab-PC1 and log in as Administrator with the password password.

Note: All captures must be text only—DO NOT capture the NotePad++ application window or the command prompt window. Use copy and paste of text only.

Task 1: Ensure that the PC_Tests Scripts are in C:\Scripts\

Open the Windows CLI Using the Desktop or Quick Launch Command Prompt icon. Change Directory to the C:\Scripts\ folder (cd \Scripts). Verify that the files PC_Tests.cmd and PC_Tests.vbs exists in this directory. If the files are absent, they can be extracted from the downloaded Doc Sharing file

Task 2: Open C:\Scripts\PC_Tests.cmd in NotePad++

Open NotePad++ and use File/Open to view the C:\Scripts\PC_Tests.cmd script file in the Editor window.

An analysis of the PC_Tests.cmd Batch script program is shown on the next page.

Task 2: Analyze the Batch Script File PC_Tests.cmd

One of the drawbacks of using VBScript instead of a full-featured programming language such as C++ or Java is the fact that VBScript does not have the capability to clear the command prompt screen. This is one of the things we need to do with our menu-driven PC_Tests program each time the menu is re-displayed. Since we can’t do this in VBScript, we will do it in a Batch script file.

Look at the PC_Tests.cmd Batch script shown on the right. The script performs the following tasks.
1. Clear the screen (CLS).
2. Display the menu.
3. Prompt the User and store the input into
4. Run the PC_Tests.vbs program and
send it the choice value (1..5) as an
argument (//nologo hides the scripting
host heading).
5. When the PC_Tests.vbs program exits
and returns to the Batch script, execute
a Pause.
6. After the user presses a key to end the
pause, go to the start of the script to
clear the screen and re-display the

A sample Batch script run of Option 1 is shown below.

Task 3: Analyze the code in the PC_Tests.vbs Program

Open the PC_Tests.vbs program in NotePad++. Let’s review some code that can tell us many important things about the computer and the Windows Operating System. Option 1 from the menu is handled by Case “1” in the Select Case statement . The VBScript code shows how to access the values of Windows Environmental variables using the WScript.Shell object’s ExpandEnvironmentStrings( ) function. Note that the environmental variables must be delimited with the % character. Do a search for Windows Environmental Variables. They can provide a wealth of information about the computer and the operating system. A Run of this code is shown below.

Option 2 from the menu is handled as Case “2” in the Select Case statement. The Case “2” code segment shows the “Check System Memory” routine. The somewhat cryptic code shown below utilizes an extremely important tool called WMI (Windows Machine Instrumentation). WMI allows you to access many underlying objects and attributes managed by the Windows OS. The variable strComputer’s value “.” refers to the local computer rather than a remote computer. See where strComputer is used when you are defining objWMIService. The ExecQuery method is used to send a query (“Select * from Win32_ComputerSystem”) to the operating system. Note that the memory size is divided by 1M...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Essay about The Clouds Analysis
  • The Clouds by Aristophanes Essay
  • Cloud Services Brokerage Essay
  • Strange Cloud Essay
  • How do clouds form Essay
  • Essay on Clouds Socrates Unjust Speech
  • Sun and High Sunlit Clouds Essay
  • Analysis of "The Clouds" by Aristophanes Research Paper

Become a StudyMode Member

Sign Up - It's Free