Tim,
Had some kind of error when I tried to post this earlier. If it's a
duplicate, I apologize.
Got this code a while back as a reply to a post I put on MS Access group. I
usually leave the the person's name in place if it came from an individual,
but I don't see it here so I can't give them credit. It may have come from
the Knowledge Base.
Anyway, used this to create code for an app that's working. Maybe it will
help.
Bruce
'READING REGISTRY ENTRIES
'------------------------
'Syntax: object.RegRead(strName)
'You can specify a key-name by ending strName with a final backslash. Do
not include
' a final backslash to specify a value-name.
'A value entry has three parts: its name, its data type, and its value.
When you specify
' a key-name (as opposed to a value-name), RegRead returns the default
value. To read a
' key's default value, specify the name of the key itself.
The RegRead method returns values of the following five types.
Type Description In the Form of
---------------------------------------------------------------------
REG_SZ A string A string
REG_DWORD A number An integer
REG_BINARY A binary value A VBArray of integers
REG_EXPAND_SZ An expandable string
(e.g., "%windir%\\calc.exe") A string
REG_MULTI_SZ An array of strings A VBArray of strings
'WRITING REGISTRY ENTRIES
'------------------------
'Syntax: object.RegWrite(strName, anyValue [,strType])
'Specify a key-name by ending strName with a final backslash. Do not
include a final
' backslash to specify a value name. The RegWrite method automatically
converts the
' parameter anyValue to either a string or an integer. The value of strType
determines
' its data type (either a string or an integer).
'The options for strType are listed in the following table:
'String REG_SZ
'String REG_EXPAND_SZ
'Integer REG_DWORD
'Integer REG_BINARY
'Note - The REG_MULTI_SZ type is not supported for the RegWrite method.
'Tip - RegWrite will write at most one DWORD to a REG_BINARY value. Larger
values
' are not supported with this method.
'Fully qualified key-names and value-names begin with a root key. You may
use abbreviated
' versions of root key names with the RegRead method. The five possible root
keys are
' listed in the following table:
' HKEY_CURRENT_USER HKCU
' HKEY_LOCAL_MACHINE HKLM
' HKEY_CLASSES_ROOT HKCR
' HKEY_USERS HKEY_USERS
' HKEY_CURRENT_CONFIG HKEY_CURRENT_CONFIG
Private Sub RegistryExample()
'Shows calls to write, read and delete registry entries.
Dim WshShell, bKey
Set WshShell = CreateObject("WScript.Shell")
'Write new key
WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\", 1, "REG_BINARY"
'Write new value
WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\MindReader",
"Goocher!", "REG_SZ"
'Read key
bKey = WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\")
'Read value
Debug.Print
WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\MindReader")
'Delete value
WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\MindReader"
'Delete key
WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\"
'Delete group
WshShell.RegDelete "HKCU\Software\ACME\"
Set WshShell = Nothing
End Sub
Public Function RegistrySearch(regSrcValue) As String
On Error GoTo NoEntry
Dim WshShell, bKey
Set WshShell = CreateObject("WScript.Shell")
bKey = WshShell.RegRead(regSrcValue)
Set WshShell = Nothing
RegistrySearch = CStr(bKey)
Exit Function
NoEntry:
RegistrySearch = ""
End Function