Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to read the name of registry keys -URGENT

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy a row 12 64
Search combo error "Data Type Mismatch in Criteria Expression" 2 68
VB 6 error 5 in windows 10 but not in XP 7 63
Collapse and expand table in Word 2010 2 32
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we 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…

856 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