Registry Routines

The Shell object provides Windows Registry access through the RegRead , RegWrite, and RegDelete methods.

When accessing a Registry key, you must specify the path. The path is built from the Registry hive name (the name of one of the major Registry branches described in Chapter 8), followed by the path to the key separated by backslash characters. Table 9-8 lists the hive names.

Table 9-8. Registry parameters

Short

Long

HKCU

HKEY_CURRENT_USER

HKLM

HKEY_LOCAL_MACHINE

HKCR

HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG
HKEY_DYN_DATA

For example, the path to the Windows version number would be represented as HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion.

One way to easily get the path for registry values is to use the RegEdit application to search for Registry information and copy the key path to the clipboard using Edit Copy Key Name. The Registry routines do not provide the ability to list any values under a particular key, so you need to know the path to any Registry values you wish to reference.

RegRead

RegRead reads the registry value from the specified Registry path:

                  strVal = objShell.RegRead(strKeyPath)

strKeyPath is a path to the Registry value you wish to read.

Set objShell = CreateObject("Wscript.Shell")
Wscript.Echo "Your Windows Version Number is " _
   & objshell.RegRead _
( "HKLM\Software\Microsoft\Windows\CurrentVersion\VersionNumber")

RegWrite

RegWrite writes a value to a specified key value or creates a new key: ...

Get Windows XP in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.