cReadEasyReg

By | 2002-06-01

A easy way to read the Registry. Most of the times I work with the registry I only want to read it, not write to it. PLEASE NOTE: This is a class module and all the code should be paste into a CLASS Module.

Original Author: Riaan Aspeling

API Declarations

‘ Developed by : Riaan Aspeling
‘ Company : Altered Reality Corporation
‘ Date : 1999-Mar-21
‘ Country : South Africa

‘ Description : A Easy way to READ the registry
‘ Comment : Most of the times a work with the registry is only want
‘ to READ it, not write to it. Hope you guys/gals out there
‘ could use this code.
‘ Problems : If you do find any problems (not Microsoft related) let me
‘ know at :
‘ arc@iti.co.za
‘ Have fun reading the registry 😉
Option Explicit
‘API’s to use
Private Declare Function RegOpenKeyEx Lib “advapi32.dll” Alias “RegOpenKeyExA” (ByVal HKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegEnumKey Lib “advapi32.dll” Alias “RegEnumKeyA” (ByVal HKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegEnumValue Lib “advapi32.dll” Alias “RegEnumValueA” (ByVal HKey As Long, ByVal dwIndex As Long, ByVal lpName As String, cbName As Long, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegQueryValueEx Lib “advapi32.dll” Alias “RegQueryValueExA” (ByVal HKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib “advapi32.dll” (ByVal HKey As Long) As Long
‘Enum’s for the OpenRegistry function
Public Enum HKeys
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_CURRENT_CONFIG = &H80000005
HKEY_DYN_DATA = &H80000006
End Enum
‘Right’s for the OpenRegistry
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private Const KEY_ALL_ACCESS = ( _
( _
STANDARD_RIGHTS_ALL Or _
KEY_QUERY_VALUE Or _
KEY_SET_VALUE Or _
KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or _
KEY_NOTIFY Or _
KEY_CREATE_LINK _
) _
And _
( _
Not SYNCHRONIZE _
) _
)
‘Local var’s to keep track of things happening
Dim RootHKey As HKeys
Dim SubDir As String
Dim HKey As Long
Dim OpenRegOk As Boolean

Code

'This function will return a array of variant with all the subkey values
'eg.
'  Dim MyVariant As Variant, MyReg As New CReadEasyReg, i As Integer
'  If Not MyReg.OpenRegistry(HKEY_LOCAL_MACHINE, "SoftwareMicrosoft") Then
'   MsgBox "Couldn't open the registry"
'   Exit Sub
'  End If
'  MyVariant = MyReg.GetAllSubDirectories
'  For i = LBound(MyVariant) To UBound(MyVariant)
'   Debug.Print MyVariant(i)
'  Next i
'  MyReg.CloseRegistry
Function GetAllSubDirectories() As Variant
On Error GoTo handelgetdirvalues
Dim SubKey_Num As Integer
Dim SubKey_Name As String
Dim Length As Long
Dim ReturnArray() As Variant

If Not OpenRegOk Then Exit Function
'Get the Dir List
SubKey_Num = 0
Do
  Length = 256
  SubKey_Name = Space$(Length)
  If RegEnumKey(HKey, SubKey_Num, SubKey_Name, Length) <> 0 Then
   Exit Do
  End If
  SubKey_Name = Left$(SubKey_Name, InStr(SubKey_Name, Chr$(0)) - 1)
  ReDim Preserve ReturnArray(SubKey_Num) As Variant
  ReturnArray(SubKey_Num) = SubKey_Name
  SubKey_Num = SubKey_Num + 1
Loop
GetAllSubDirectories = ReturnArray
Exit Function
handelgetdirvalues:
GetAllSubDirectories = Null
Exit Function
End Function
'This function will return a array of variant with all the value names in a key
'eg.
'  Dim MyVariant As Variant, MyReg As New CReadEasyReg, i As Integer
'  If Not MyReg.OpenRegistry(HKEY_LOCAL_MACHINE, "HardWareDescriptionSystemCentralProcessor

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.