DOWNLOAD THE CODE:
Download the Code 40714.zip

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 -->



You must log on before posting a comment.

If you don't have a username & password, please register now.

Reader Comments

Can this same script be used to just reada remote registries and generate a report?

rsharma

Where is the link to the 40714.zip file referneced above. I can not find any such link.

Steven Sutherland

Enjoyed the article, I think ApplyReg.vbs could become(IS)a valuable utility. However, after I entered 40714 (Enter 40714 in the InstantDocID text box, click the Download the Code link) I'm unable to find this link on the page. What am I overlooking ?? My co-worker has the subscription and she doesn't see it either.

Michael Radzymski

I could not find the 'download the code' link mentioned in this article....

Dale

In what situation would you use ApplyReg.vbs, and how common is it use in networks.

lewis bailey

Since most environments are not strictly microsoft ad, how would you modify the script to use netbios names instead of using the fqdn?

Louis

<P>I very much enjoyed this article about updating remote registries. I am always looking for articles like this that show more advanced scripting because I write a lot of VBScripts. I reviewed ApplyReg.vbs and just want to make a couple of remarks. </P>

<P>When I write scripts that perform actions on a series of remote computers, I also have a function that checks whether the remote computer is reachable. Instead of using Ping and reading the output to determine whether the remote machine answered, I prefer to use the Win32_PingStatus WMI class, which is available in Windows XP and Windows Server 2003, for a couple of reasons. First, I think that this method is a more elegant approach to this task. Second, we work in an environment with computers in 5 different countries in Europe, all of which use their local language on their machines. Writing a script that reads the output of a command-line command is difficult when multiple languages are involved.</P>

The other thing I would like to mention is that NetBIOS or Fully Qualified Domain Names (FQDNs) are always easier to remember than distinguished names (DNs). I wrote scripts that used a text file with server NetBIOS names as the input file. I then used ADO to make an Active Directory (AD) search when I need the DN of the server. Because a small function looks up the DN, you don’t have to prepare the input file that you suggested with the DN already in the text file. Using a function to get the DN has another slight advantage: You can reuse the function in every script that requires a DN.

<P><B>A note from Ethan:</B> I’m aware of the Win32_PingStatus class, and I agree with you that this is the best approach. Just to give you some history, I specifically choose the approach I took because the Windows Resource Kit team originally asked me to write these scripts and the team told me that I must make the tool work in a pure Windows 2000 environment. I couldn't even rely on having a Windows XP client for running the script. As a result, I went with the non-localized approach of reading the "reply from..." message. Your approach is much better when you can assume that one client is running Windows XP.</P> <P>You make another great point about using DNs instead of FQDNs or NetBIOS names in the script. Again, a little history is in order. The goal was to take the output from another script as the input for the ApplyReg script. The output from the other script was the DNs of all domain controllers in a domain. If you get a chance, take a look at the two white papers that I reference in the article. The scripts, including ApplyReg, were written specifically to support the security goals delineated in the white paper.</P>

Stefan

Hi! I´ve enjoyed a lot reading this article because it helped me very much. I just have one question to make to you that is what if a computer in my network is not available at the time i´m updating the registry´s, the script creates a loop that when the machine is available it sends the new keys or if not how can i resolve this issue???

Thanks a lot!!!

Mario Raposo

Can this script be used to change permissions on reg keys?

JC

Ethan--excellent script, I am now using it all the time.

One problem however... When the CreateDWORD subroutine converts the hex value using CInt, it can't handle large numbers. For example, it will fail converting the hex value '00010000', and therefore will not write that value to the registry. I resolved this by changing CInt to CLng.

mvanwely

Article Rating 5 out of 5

I cant find your sample AAA123Test!!!.reg

Can u direct me there?

Anonymous User

Overkill, for what is essentially a very simple procedure

Anonymous User

Article Rating 1 out of 5

I am getting the following error "Report records processed: C:\Documents and Settings\spilmanr\My Documents\Tools\Remote Registry Tool\apply reg.vbs(469, 3) Microsoft VBScript runtime error: Invalid procedure call or argu ment: 'Mid'"

Anyone help?

Anonymous User

Article Rating 5 out of 5

 
 

ADS BY GOOGLE