Solved

How to read the name of registry keys -URGENT

Posted on 2001-07-24
1
185 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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