Other methods to set Registry key values

One of the interesting things about automation, and scripting in general, there are always multiple ways to solve a problem. In yesterday’s blog, the original question “How do set DWord values in a VBScript?” was solved this way.

There were 3 other methods (actually 2 new, one enhancement) posted yesterday that are interesting, and worth breaking down.

Method 1

Using regedit and merging the registry keys. Now; this method has been around for a long time (the article references Windows 3.1 :), and have used it myself with great results. Jeff Gilbert was kind enough to post the method and a link to the article.

Just save the regedit (modify a computer registry and export the key) and add the command line to the program/mst by using

regedit /s:REGEDIT /S /U <your .reg goes here>

http://support.microsoft.com/kb/82814/en-us

Additionally, you could set this as a package/program option in SMS/SCCM making this perhaps the most simple.

Method 2

Using the WScript RegWrite method.

Here’s a partial breakdown (see the link for full disclosure):

Creates a new key, adds another value-name to an existing key (and assigns it a value), or changes the value of an existing value-name.

object.RegWrite(strName, anyValue [,strType])

It is somewhat shortened by a few lines of code (thanks to Sherry Kissinger for the code sample):

Set oWS = Wscript.CreateObject("Wscript.Shell")
‘ Single line each, watch line wrap

oWS.RegWrite "HKLM\SOFTWARE\JavaSoft\Java Update\Policy\EnableJavaUpdate", "00000000", "REG_DWORD"

oWS.RegWrite "HKLM\SOFTWARE\JavaSoft\Java Update\Policy\NotifyDownload", "00000000", "REG_DWORD"

Method 3

Using the same method that I posted yesterday, Maarten van Willigen used an array to enumerate the key names and set the values (note: this works because each of the keys being set are DWord). Simplification is good, also very creative solution.

const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set objRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_

strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\JavaSoft\Java Update\Policy"

For Each strValueName In Array("EnableJavaUpdate","NotifyDownload","NotifyInstall")

  dwValue = "0"

  objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

Next

Summary

As many of you know, I'm partial to scripting based solutions. However, sometimes whatever gets the job done is OK as well.

In a future blog, I'll post an example of why scripting and scripting solutions in general is a vitally important item to learn.

I know there are other ways and languages to solve this, comments, suggestions? Let me know what you think.

Published Friday, February 08, 2008 12:20 PM by sthompson
Filed under: ,

Comments

# Other methods to set Registry key values &laquo; Java Net

Monday, February 11, 2008 7:31 AM by Other methods to set Registry key values « Java Net

Pingback from  Other methods to set Registry key values &laquo; Java Net

Powered by Community Server (Commercial Edition), by Telligent Systems