Previous Page
Next Page

One Step Further: Modifying the Ping Script

In this section, you will modify the ping script so that it can be used to monitor your servers.

1.
Open pingSolution.vbs and save it as YourNamePingModification.vbs.

2.
Comment out On Error Resume Next so that you can test the script.

3.
Define a constant called ONE_HOUR and set it equal to 100 for testing purposes. The WScript.Sleep command takes an argument in milliseconds. So normally you would set ONE_HOUR to 3600000, which is one hour in milliseconds.

4.
Declare a variable to be used to count to eight, such as ihours.

5.
Add a For ihours = 1 To 8 command to the beginning of the Worker section. It will go under aMachines = Split(strMachines, ";").

6.
Add the WScript.Sleep(ONE_HOUR) command to the bottom of the script (after all those Next commands). When you define a constant as you did in step 3, testing your script is a lot nicer.

7.
Save the script. Try to run the script. (You should get an error.)

8.
Add another Next command after the WScript.Sleep command.

9.
Save the script and run it. (It should work now.)

10.
Add a WScript.Echo command to the bottom of the script with a message letting you know when the script is finished.

Chapter 2 Quick Reference

To

Do This

Walk through a collection of items such as is often returned by WMI

Use For Each...Next

Define numbers that could be confusing if they were embedded within a script

Use a constant

Make a script easier to read, and easier to modify in the future

Use a constant

Modify a value during script execution

Use a variable

Perform an operation a certain number of times

Use For...Next

Create a looping condition that occurs only as long as a particular condition is true

Use Do While...Loop

Create a looping condition that occurs until a particular condition becomes true

Use Do Until...Loop

Pause script execution

Use WScript.Sleep

Pause script execution for five seconds

Use WScript.Sleep(5000)



Previous Page
Next Page