COMP230 Week 5 Lab VBScript Modular Programming Lab
Download here: http://homeworkfox.com/questions/computer-science/11716/comp23
system. A Run of this code is shown belo · 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 * fromWin32_ComputerSystem”) to the operating system. Note that the memory size is divided by 1M (1048576) so the answer can be expressed in Mbytes instead of Bytes. The run is shown below the script code. · Option 3 from the menu is handled as Case “3” in the Select Case statement. The Case “3” code segment shows the “Check Operating System Version” routine. Note that this program makes use of the same objWMIService definition as the last program. Again we use the ExecQuery method to send a query to the Windows OS. Note, however, that query has a different target (“Select * fromWin32_OperatingSystem). Notice also that the ExecQuery method always returns a collection objectcolOperatingSystems. An ExecQuery can return more than one record so we need to handle the display in a For Each/Next loop. · The next VBScript code routine is for “Check Printers Status”. This routine, like the last two, defines theobjWMIService object in exactly the same way. This time the W32_Printer is queried. A run of the Check Printers Status routine is shown on the next page. · Option 5 is handled by Case “5” in the Select Case statement. The “Check Logical Drive Information” routine also uses the objWMIService. The ExecQuery method sends a query to the W32_LogicalDiskobject and the query is modified with Where FreeSpace > 0. The where clause ensures we will not display the CDROM or DVD drives. The Size and FreeSpace are divided by 1G (1073741824) to display the sizes in Gb · Open a Windows CLI as Administrator and run the PC_Tests.cmd Batch file (C:\PC_Tests.cmd <Enter>). The Batch script will clear the screen and display the PC Tests menu. After a choice is made, the PC_Tests.vbs program is run using cscript · Run all of the PC Tests and see what happens when you enter incorrect menu choices. Is there any error-handling incorrect menu choices? Make sure that everything is functional before you start your Task 4 modifications. Task 4: Make the PC_Tests.vbs Program Modular · Programs and scripts can be easier to write, modify, and debug when the major tasks of the program are written as separate identifiable modules. VBScript allows for two kinds of modules: functions and procedures. Functions are unique in that they always return a value. Functions are typically used to input a single value or to perform a calculation. Procedures, however, do not return a value. Procedures, rather, perform a task. · Our first modification to the PC_Tests.vbs will involve re-writing the five tasks described in Task 3 as separate procedures. Before we get started, Save As the PC_Tests.vbs program as Mod1_PCTests.vbs. Cut and copy all of the code for Case “1” in the Select Case statement and paste it below the Select Case statement. Add a line above this code that reads: Sub System_Information. After the last line of the pasted code, add the line End Sub. Go back to Case “1” in the Select Case statement and add the line Call System_Information. The completed procedure (or SubRoutine) for System_Information is shown below the modified Select Case statement. Continue these modifications until each of the PC Test routines have been re-written as procedures (Subs). Make sure that all lines are properly indented for the Subs and the