Solved

How to read the name of registry keys -URGENT

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

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 127
TT Auto Dashboard 13 100
Macro Excel - Multiple If conditions 2 87
pop out of webbrowser1 control vba6 5 41
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

679 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