Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

How to read the name of registry keys -URGENT

Hi Everybody,

I have this registry setting :
HKEY_CURRENT_USER
     Software\strategic\id\Pages\Page1
                                \Page2
                                \Page3

If my application does'nt know there are 3 pages and that I need to retrieve the 3 names (Page1,Page2,Page3) in 1 string...How can I do it?

The same qst with the values...how can I put more than 1 value in page1 and how do I retrieve all of them?

Thank's for your help...it'll save my...

Rich

0
richardferron
Asked:
richardferron
1 Solution
 
ArkCommented:
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 RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue 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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const MAX_SIZE = 2048
Private Const HKCU = &H80000001
Private Const ERROR_SUCCESS = 0&
Private Const KEY_ALL_ACCESS = &HF003F

Private Function EnumSubKeys(TopKey As Long, SubKey As String, KeyName() As String, KeyValue() As String) As Long
   Dim hKey As Long, curidx As Long
   Dim nImage As Integer, sSndFile As String, sSndMode As String
   ReDim KeyName(0)
   ReDim KeyValue(0)
   RegOpenKeyEx TopKey, SubKey, 0&, KEY_ALL_ACCESS, hKey
   On Error Resume Next
   Do
     KeyName(curidx) = Space$(MAX_SIZE)
     KeyValue(curidx) = Space$(MAX_SIZE)
     If RegEnumKey(hKey, curidx, KeyName(curidx), MAX_SIZE) <> ERROR_SUCCESS Then Exit Do
     KeyName(curidx) = TrimNull(KeyName(curidx))
     If RegQueryValue(hKey, KeyName(curidx), KeyValue(curidx), MAX_SIZE) <> ERROR_SUCCESS Then Exit Do
     KeyValue(curidx) = TrimNull(KeyValue(curidx))
     If KeyValue(curidx) = "" Then KeyValue(curidx) = KeyName(curidx)
     curidx = curidx + 1
     ReDim Preserve KeyName(curidx)
     ReDim Preserve KeyValue(curidx)
   Loop
   On Error GoTo 0
   RegCloseKey hKey
   EnumSubKeys = curidx
End Function

Private Function TrimNull(startstr As String) As String
   Dim pos As Integer
   pos = InStr(startstr, Chr$(0))
   If pos Then
      TrimNull = Left$(startstr, pos - 1)
      Exit Function
   End If
   TrimNull = startstr
End Function

Private Sub Command1_Click()
  Dim nSubKeys As Long
  Dim KeyName() As String, KeyValue() As String
  nSubKeys = EnumSubKeys(HKCU, "Software\strategic\id\Pages", KeyName, KeyValue)
  For i = 0 To nSubKeys - 1
     Debug.Print KeyName(i), KeyValue(i)
  Next i
End Sub

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now