RegEnumKeyEx 
Author Message
 RegEnumKeyEx

Hi,

I have had absolutely no success getting this method to work in eVB.
The RegEnumKeyEx Method always returns an empty string. What am i doing
wrong?!?
I've tried everything!
Need Help.
Thanks,
Boris

-------

Public Declare Function RegOpenKeyEx Lib "Coredll" Alias "RegOpenKeyExW"
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long,
ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegEnumKeyEx Lib "Coredll" Alias "RegEnumKeyExW"
(ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName
As Long, ByVal Reserved As Long, ByVal lpClass As String, lpcbClass As Long,
lpftLastWriteTime As Long) As Long
Public Declare Function RegQueryInfoKey Lib "Coredll" Alias
"RegQueryInfoKeyW" (ByVal hKey As Long, ByVal lpClass As String, lpcbClass
As Long, ByVal lpReserved As Long, lpcSubKeys As Long, lpcbMaxSubKeyLen As
Long, lpcbMaxClassLen As Long, lpcValues As Long, lpcbMaxValueNameLen As
Long, lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long,
lpftLastWriteTime As Long) As Long

Public Function CEEnumKey(ByRef strError As Variant, ByVal APPNAME As
String, _
ByVal Section As String) As Variant

On Error Resume Next

Dim lngSize As Long
Dim hlngSubKey As Long
Dim lngResult As Long
Dim Key_Read As Long
Dim SubKey As String
Dim udtLastWriteTime    As String
Dim saSubkeys() As String
Dim lIndex As Long: lIndex = 0
Dim Key As String
Dim lngSubKeyCount As Long
Dim lngMaxSubKeyLength As Long
Dim FileTime As Currency
Dim lngKeyLength As Long
  'False until proven true...
  udtLastWriteTime = String(8, 0)
  'Key_Read = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  Key_Read = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or
KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or
KEY_CREATE_LINK) And (Not SYNCHRONIZE))

  'Fill the "Setting" parameter with 256 chr(0)'s
  lngSize = 255
  SubKey = APPNAME & "\" & Section

  'Open the registry key and find a handle to the sub key
  'It is always under HKEY_LOCAL_MACHINE
  'Return hlngSubKey, lngResult indicates success or failure
  lngResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SubKey, 0, Key_Read,
hlngSubKey)
  If (lngResult <> ERROR_SUCCESS) Then
    strError = "CEGetSetting: Unable to open the registry sub-key '" &
SubKey & "'."
    Exit Function
  End If

  'Try to read the value of the item
  'Pass in hlngSubKey and the Key we are looking for.
  'Setting is 256 chr(0) on the way in (Byref).
  'Return lngType, strItemValue, lngSize
    lngResult = RegQueryInfoKey(hlngSubKey, vbNullString, 0, 0,
lngSubKeyCount, lngMaxSubKeyLength, 0, 0, 0, 0, 0, 0)

      For lIndex = 0 To lngSubKeyCount - 1
        lngKeyLength = lngMaxSubKeyLength + 1
        Key = String(lngMaxSubKeyLength + 1, 0)
        Dim temp As Long: temp = 0
        lngResult = RegEnumKeyEx(hlngSubKey, lIndex, Key, lngKeyLength, 0,
vbNullString, 0, 0)
        MsgBox Key
        'If res = ERROR_SUCCESS Then
          '  strItem = Left(strKeyName, lngKeyLength)
          '  cTemp.Add strItem, strItem
        'End If
    Next lIndex

    'While lngResult = ERROR_SUCCESS
      '  Key = String(lngSize, 0)
     '   lngResult = RegQueryInfoKey(hlngSubKey, vbNullString, 0, 0,
lngSubKeyCount, lngMaxSubKeyLength, 0, 0, 0, 0, 0, 0)
     '   MsgBox lngSubKeyCount
     '   lngResult = RegEnumKeyEx(hlngSubKey, lIndex, Key, lngSize, 0,
vbNullString, 0, udtLastWriteTime)
        'MsgBox Key
      '  If lngResult = ERROR_SUCCESS Then
      '          ReDim Preserve saSubkeys(lIndex)
      '          saSubkeys(lIndex) = Left(Key, lngSize)   'strip off
trailing null
      '          lIndex = lIndex + 1
       '         lngSize = 255   'reset default buffer size
      '  ElseIf lngResult = ERROR_MORE_DATA Then
                'lBuffLen now contains required buffer size, so loop
      '          lngResult = ERROR_SUCCESS
      '  End If
   ' Wend
 ' If lngResult <> ERROR_NO_MORE_ITEMS Then
 '   strError = "Registry items not Enumerated"
 'End If

  If lIndex > 0 Then
        GetAllSubkeys = saSubkeys
  End If

  strError = ""
  Key = CleanString(Key)
  MsgBox Key
  CEEnumKey = True

End Function



Tue, 20 Jan 2004 06:18:49 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Using RegEnumKeyEx

2. RegEnumKeyEx

3. Newbie : API call RegEnumKeyEx

4. help with RegEnumKeyEx

5. RegEnumKeyEx on NT4

6. Help w/RegEnumKeyEx

7. Why RegEnumKeyEx does not return subkey of registry

8. Stumped RegOpenKeyEx, RegQueryInfoKey, RegEnumKeyEx under NT Using VB5

9. RegEnumKeyEx and Windows 2000

10. RegEnumKeyEx, FILETIME

11. Using RegEnumKeyEx in VB

12. RegEnumKeyEx results in API error 87 - Parameter Incorrect

 

 
Powered by phpBB® Forum Software