Next, VBScript's Split function teases apart the BindDN function's output by using two pipe symbols (||) as a delimiter. The Split function assigns the resulting three pieces of information to the arrComputerInfo array, as callout A in Web Listing 6 shows. The script uses this array for code evaluation and for writing information to the report. The first item in the array, arrComputerInfo(0), contains the computer's DN, which the script assigns to the strDN variable. The second item in the array, arrComputerInfo(1), contains the computer name, which the script assigns to the strComputerName variable. The value is None, the host name, or the NetBIOS name. The third item in the array, arrComputerInfo(2), contains general information, which the script assigns to the strNote variable. This value is Invalid, Host, or NetBIOS.
Why bother going to the trouble of attempting a binding operation and retrieving AD attributes? Because before updating a computer's registry, the script must make sure it can find the target computer. If the computer exists in AD and BindDN returns a dNSHostName or cn attribute, ApplyReg.vbs attempts to ping the computer on the network by using the computer's DNS name or NetBIOS name. To accomplish this task, the script loads the WshShell object and uses this object to call the Ping utility, as Web Listing 7 shows. This procedure is a good way to find computers that are online. For more information about why this procedure is a good choice for finding computers that are online, see "Remote Administration with WMI," February 2003, http://www.winscriptingsolutions.com, InstantDoc ID 37596. Another good resource is "Tales from the Script - November 2002" (http://www.microsoft.com/technet/treeview/default.asp?url=/technet/columns/scripts/sg1102.asp?frame=true).
When the ping succeeds, the script attempts to connect to StdRegProv, as callout A in Web Listing 7 shows. When the connection attempt succeeds, ApplyReg.vbs performs the registry update. To perform the update, the script reads each line of the registry file and sets the strLine variable equal to the line's value. Then RegExp evaluates the pattern in strLine. When the pattern matches a key value, WMI's CreateKey method creates the key, as the code in Listing 2 shows. If no match occurs for a key pattern, the script tests each possible value name that's allowed in the registry. When a pattern match occurs, ApplyReg.vbs calls the appropriate routine. The code in Listing 3 shows the pattern matches that the script attempts for each type of entry and the name of the subroutine that the script calls when a pattern match occurs. If you're unfamiliar with regular expressions and would like a primer, see Stephen Ramsay's excellent article, "Using Regular Expressions" (http://etext.lib.virginia.edu/helpsheets/regex.html).
After the script reads all the lines of the registry file, the script sets the strStatus variable to Registry update applied. If the host is unreachable because the ping operation didn't return a reply, the script sets strStatus to Host unreachable and strNotes to Verify that this host is online. Then, the FileSystemObject's WriteLine method writes the values contained in strDN, strComputer, strStatus, and strNotes to the report file. After the script processes all the lines in the input file, you'll see a console message that states the report data has been saved.
It's Time to Save Time
Preparing to use ApplyReg.vbs involves downloading the script, creating a registry file, building a list of computer names, and thoroughly testing the script in the lab. If everything checks out, you're ready to use ApplyReg in a production network. Make updates on a small subset of your production computers until you're satisfied that the registry update is working properly. If everything checks out, your careful testing and cautious deployment will save you countless hours of performing manual registry updates.
End of Article
Prev. page
1
2
3
[4]
next page -->