Enhancing Your ScriptYou've worked your way through your first script, and now let's see how we can modify it to enhance its capabilities. Here is the new functionality you will add to your script:
Let's first add some documentation to the script so that when you look at it six months from now, you'll know what you're looking at. To add documentation, you simply type information into the script. To prevent the script from choking, you need to indicate that you are adding the text. You can do this in several ways. Perhaps the most efficient way is to preface each note with a single quotation mark (') followed by explanatory text (often called a comment). If you are wondering what kinds of documentation you might want to include in your script, you can refer to Appendix D, "Documentation Standards," which provides guidance on the kinds of information you may want to include in each of the four sections of the script. Here's what the script looks like with the added documentation: DisplayComputerNamesWithComments.vbs 'This script displays various Computer Names by reading the registry Option Explicit 'forces the scripter to declare variables On Error Resume Next 'tells VBScript to go to the next line 'instead of exiting when an error occurs 'Dim is used to declare variable names that are used in the script Dim objShell Dim regActiveComputerName, regComputerName, regHostname Dim ActiveComputerName, ComputerName, Hostname 'When you use a variable name and then an equal sign (=) 'you're saying the variable contains the information on the right. 'The registry keys are quite long, so make them easier to read on 'a single screen by splitting the line in two. regActiveComputerName = "HKLM\SYSTEM\CurrentControlSet" & _ "\Control\ComputerName\ActiveComputerName\ComputerName" regComputerName = "HKLM\SYSTEM\CurrentControlSet\Control" & _ "\ComputerName\ComputerName\ComputerName" regHostname = "HKLM\SYSTEM\CurrentControlSet\Services" & _ "\Tcpip\Parameters\Hostname" Set objShell = CreateObject("WScript.Shell") ActiveComputerName = objShell.RegRead(regActiveComputerName) ComputerName = objShell.RegRead(regComputerName) Hostname = objShell.RegRead(regHostname) 'To make dialog boxes you can use WScript.Echo 'and then tell it what you want it to say. WScript.Echo activecomputername & " is active computer name" WScript.Echo ComputerName & " is computer name" WScript.Echo Hostname & " is host name" Just the Steps ![]() |