Solved

How to read the name of registry keys -URGENT

Posted on 2001-07-24
1
180 Views
Last Modified: 2010-05-02
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
Comment
Question by:richardferron
1 Comment
 
LVL 27

Accepted Solution

by:
Ark earned 200 total points
ID: 6315748
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now