Previous Page
Next Page

One Step Further: Customizing an Existing Script

This section will provide addional practice and illustrate the important technique of customizing an existing script. It is common knowledge that when confronted with the task of creating a script, most network administrators often start with a script they found on the Internet. It is, however, important for the administrator to customize the script and ensure that only the most useful portions of the script are left behind prior to deployment.

Scenario

You are a new network administrator at a Fortune 500 company. You recently had a server crash, and it did not generate a dump file. Because you have several servers on your network, you don't want to have to "mouse around" very much; rather, you'd like to simply run a script to confirm the crash recovery configuration. Because your company is fortunate to have a college intern working for the summer, and you haven't yet learned how to remotely run the script, you've decided to do the following:

1.
Create a script that reads crash recovery information from the registry. Your research has revealed the following keys to be of interest:

"HKLM\SYSTEM\CurrentControlSet\Control\CrashControl\AutoReboot"
"HKLM\SYSTEM\CurrentControlSet\Control\CrashControl\MinidumpDir"
"HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname"
"HKLM\SYSTEM\CurrentControlSet\Control\CrashControl\LogEvent"
"HKLM\SYSTEM\CurrentControlSet\Control\CrashControl\DumpFile"

2.
Copy the script to a share on a local server.

3.
Run the script under CScript.

4.
Have the intern copy the output from the command prompt and paste it into a Notepad file that has the same name as the server.

Step-by-Step Instructions
1.
Open the \My Documents\Microsoft Press\VBScriptSBS\ch01\OneStepFurther\CustomizeExistingScript.vbs file and save it as YourNameCustomizeExistingScript.vbs.

2.
Edit the Header information section of the script and include variables for each of the items you are going to read from the registry. (Remember, you'll need two variables for each registry item: one for the registry key itself, and one for the data contained in the registry key.)

3.
Edit the Reference information section of the script. (Use the reg variable names you created in step 2 of this procedure and assign them to the appropriate registry keys.)

4.
Edit the Worker information section of the script. (Assign the non-registry variable names you created in step 2 to the regRead Worker part of the script.)

5.
Edit the Output information section of the script. (Use the same variables you assigned to the regRead parts in step 4.)

6.
Add any documentation you need to the script. (Make sure you over-comment your script. Concepts that are perfectly clear today will be a dull memory within a few days.)

7.
Save your script.

8.
Open a command prompt.

9.
Type CScript YourNameCustomizeExistingScript.vbs and press Enter. (If you get a File Not Found comment, change to the directory where you saved your script and repeat the command.)

Chapter 1 Quick Reference

To

Do This

Catch misspelled variable names

Use Option Explicit on the first line of your script

Declare a variable

Use the Dim command, followed by the variable name

Continue to the next line, following an error

Use On Error Resume Next

Produce a pop-up dialog box when you double-click on a script

Use WScript.Echo

Produce a line of output when running a script under CScript at a CMD prompt

Use WScript.Echo

Create an object

Use the CreateObject command followed by the name of the automation object to create

Run a script under the default scripting host

Double-click on the script

Run a script under CScript

Open a CMD prompt and precede the name of the script with the command CScript

Add documentation to a script

Precede the comment with a single quotation mark'



Previous Page
Next Page