This can be built on, but I've not needed to so far.
This is used in my database(s) and stored as modOS.
[CODE=vb]
Option Compare Database
Option Explicit
Public Const conHKCR = &H80000000
Public Const conHKCU = &H80000001
Public Const conHKLM = &H80000002
Public Const conHKU = &H80000003
Public Const conStandardRigh tsAll = &H1F0000
Public Const conReadControl = &H20000
Public Const conStandardRigh tsRead = (conReadControl )
Public Const conRegSz = 1
Public Const conOK = 0&
Public Const conKeyQueryValu e = &H1
Public Const conKeySetValue = &H2
Public Const conKeyCreateLin k = &H20
Public Const conKeyCreateSub Key = &H4
Public Const conKeyEnumerate SubKeys = &H8
Public Const conKeyNotify = &H10
Public Const conSynchronise = &H100000
Public Const conRegOptionNon Volatile = 0
Public Const conKeyAllAccess = ((conStandardRi ghtsAll Or _
conKeyQueryValu e Or _
conKeySetValue Or _
conKeyCreateSub Key Or _
conKeyEnumerate SubKeys Or _
conKeyNotify Or _
conKeyCreateLin k) And _
(Not conSynchronise) )
Public Const conKeyRead = ((conReadContro l Or _
conKeyQueryValu e Or _
conKeyEnumerate SubKeys Or _
conKeyNotify) And _
(Not conSynchronise) )
Private Declare Function RegOpenKeyEx Lib "advapi32.d ll" _
Alias "RegOpenKey ExA" (ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.d ll" (ByVal hKey As Long) _
As Long
Private Declare Function RegQueryValueEx Str Lib "advapi32.d ll" _
Alias "RegQueryValueE xA" (ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
lpType As Long, _
ByVal lpData As String, _
lpcbData As Long) As Long
Public Function RegRead(ByVal lngHive As Long, _
ByVal strKey As String, _
ByVal strValue As String) As Variant
Dim intIdx As Integer, intHK As Integer
Dim strWork As String
Dim lngRet As Long, lngLen As Long, lngHKey As Long, lngType As Long
RegRead = Null
strKey = strKey & Chr(0)
lngRet = RegOpenKeyEx(ln gHive, strKey, 0, conKeyRead, lngHKey)
If lngRet = conOK Then
'Create buffer to store value
strWork = Space(255)
lngLen = 255
lngRet = RegQueryValueEx Str(lngHKey, _
strValue, _
0&, _
lngType, _
strWork, _
lngLen)
RegRead = Left(strWork, lngLen - 1)
If Len(RegRead) = 254 Then RegRead = Null
'Close key
Call RegCloseKey(lng HKey)
End If
End Function[/CODE]
This is used in my database(s) and stored as modOS.
[CODE=vb]
Option Compare Database
Option Explicit
Public Const conHKCR = &H80000000
Public Const conHKCU = &H80000001
Public Const conHKLM = &H80000002
Public Const conHKU = &H80000003
Public Const conStandardRigh tsAll = &H1F0000
Public Const conReadControl = &H20000
Public Const conStandardRigh tsRead = (conReadControl )
Public Const conRegSz = 1
Public Const conOK = 0&
Public Const conKeyQueryValu e = &H1
Public Const conKeySetValue = &H2
Public Const conKeyCreateLin k = &H20
Public Const conKeyCreateSub Key = &H4
Public Const conKeyEnumerate SubKeys = &H8
Public Const conKeyNotify = &H10
Public Const conSynchronise = &H100000
Public Const conRegOptionNon Volatile = 0
Public Const conKeyAllAccess = ((conStandardRi ghtsAll Or _
conKeyQueryValu e Or _
conKeySetValue Or _
conKeyCreateSub Key Or _
conKeyEnumerate SubKeys Or _
conKeyNotify Or _
conKeyCreateLin k) And _
(Not conSynchronise) )
Public Const conKeyRead = ((conReadContro l Or _
conKeyQueryValu e Or _
conKeyEnumerate SubKeys Or _
conKeyNotify) And _
(Not conSynchronise) )
Private Declare Function RegOpenKeyEx Lib "advapi32.d ll" _
Alias "RegOpenKey ExA" (ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.d ll" (ByVal hKey As Long) _
As Long
Private Declare Function RegQueryValueEx Str Lib "advapi32.d ll" _
Alias "RegQueryValueE xA" (ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
lpType As Long, _
ByVal lpData As String, _
lpcbData As Long) As Long
Public Function RegRead(ByVal lngHive As Long, _
ByVal strKey As String, _
ByVal strValue As String) As Variant
Dim intIdx As Integer, intHK As Integer
Dim strWork As String
Dim lngRet As Long, lngLen As Long, lngHKey As Long, lngType As Long
RegRead = Null
strKey = strKey & Chr(0)
lngRet = RegOpenKeyEx(ln gHive, strKey, 0, conKeyRead, lngHKey)
If lngRet = conOK Then
'Create buffer to store value
strWork = Space(255)
lngLen = 255
lngRet = RegQueryValueEx Str(lngHKey, _
strValue, _
0&, _
lngType, _
strWork, _
lngLen)
RegRead = Left(strWork, lngLen - 1)
If Len(RegRead) = 254 Then RegRead = Null
'Close key
Call RegCloseKey(lng HKey)
End If
End Function[/CODE]
Comment