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 |
|---|---|
|
|
HKEY_CURRENT_USER |
|
|
HKEY_LOCAL_MACHINE |
|
|
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access