Getting all registry Keys in a directory 
Author Message
 Getting all registry Keys in a directory

Hello and Thanks in advance.

I am doing a minor login box for apps that are not networked. I am setting
up an area in the Registry for Login(key) and Password (value).
I can write the entry and read a Pasword(Value)  if I know the login(Key).
(RegistryKey in the example)

How do I find all the Keys / Logins in this section? There has to be a
method because Regedit32 can do it.

My function to read if I know the Key:
Public Function fncRegistryRead(RegistryRoot As enuRegRootName, RegistryHive
As String, RegistryKey As String) As String
On Error GoTo ErrorHandle
    Dim hKey As Long
    Dim strkey As String * 255
    Dim lngSize As Long
    Dim lngType As Long
    Dim lResult As Long
    lngSize = 255

    If RegOpenKey(RegistryRoot, RegistryHive, hKey) Then
        Err.Raise 1000, "fncRegistryRead", "Key Not Found: " & RegistryRoot
& "\" & RegistryHive
        Exit Function
    End If
    lResult = RegQueryValueEx(hKey, RegistryKey, 0, lngType, ByVal strkey,
lngSize)
    If lResult = ERROR_SUCCESS Then
        If lngType = REG_SZ Then
            If lngSize > 0 Then lngSize = lngSize - 1
            fncRegistryRead = Left$(strkey, lngSize)
        End If
    End If

Exit Function
ErrorHandle:
    'do my stuff that needs more code than you want to see.
End Function



Wed, 18 Jun 1902 08:00:00 GMT  
 Getting all registry Keys in a directory
I figured it out

Public Function fncRegistryEnumerate(RegistryRoot As enuRegRootName,
RegistryHive As String) As Variant
On Error GoTo ErrorHandle
  Dim ThisFileTime As typeFileTime
  Dim hKey As Long
  Dim Result As Long
  Dim Index As Long
  Dim keyname As String
  Dim classname As String
  Dim keylen As Long
  Dim classlen As Long
  Dim Message As Variant
  Dim Reserved As Long

'    Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SYSTEM\CurrentControlSet\Control\Print\Printers", 0, KEY_READ, hKey)
'    Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\Micromonitors\TrueGasHost\Security\", 0, KEY_READ, hKey)
    Result = RegOpenKeyEx(RegistryRoot, RegistryHive, 0, KEY_READ, hKey)
    If Result <> ERROR_SUCCESS Then
'        MsgBox "Can't open key"
        fncRegistryEnumerate = ""
        Exit Function
    End If
    Do
        keylen = 2000
        classlen = 2000
        keyname = String$(keylen, 0)
        classname = String$(classlen, 0)
        Result = RegEnumKeyEx(hKey, Index, keyname, keylen, Reserved,
classname, classlen, ThisFileTime)
        Index = Index + 1

        If Result = ERROR_SUCCESS Then
          Message(Tools.fncRedimArray(Message, 1)) = Left$(keyname, keylen)
        End If 'Result = ERROR_SUCCESS

    Loop While Result = ERROR_SUCCESS

    fncRegistryEnumerate = Message

    RegCloseKey hKey

End Function

TW Scannell, MCP


Quote:
> Hello and Thanks in advance.

> I am doing a minor login box for apps that are not networked. I am setting
> up an area in the Registry for Login(key) and Password (value).
> I can write the entry and read a Pasword(Value)  if I know the login(Key).
> (RegistryKey in the example)

> How do I find all the Keys / Logins in this section? There has to be a
> method because Regedit32 can do it.

> My function to read if I know the Key:
> Public Function fncRegistryRead(RegistryRoot As enuRegRootName,
RegistryHive
> As String, RegistryKey As String) As String
> On Error GoTo ErrorHandle
>     Dim hKey As Long
>     Dim strkey As String * 255
>     Dim lngSize As Long
>     Dim lngType As Long
>     Dim lResult As Long
>     lngSize = 255

>     If RegOpenKey(RegistryRoot, RegistryHive, hKey) Then
>         Err.Raise 1000, "fncRegistryRead", "Key Not Found: " &
RegistryRoot
> & "\" & RegistryHive
>         Exit Function
>     End If
>     lResult = RegQueryValueEx(hKey, RegistryKey, 0, lngType, ByVal strkey,
> lngSize)
>     If lResult = ERROR_SUCCESS Then
>         If lngType = REG_SZ Then
>             If lngSize > 0 Then lngSize = lngSize - 1
>             fncRegistryRead = Left$(strkey, lngSize)
>         End If
>     End If

> Exit Function
> ErrorHandle:
>     'do my stuff that needs more code than you want to see.
> End Function



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Getting a registry key

2. Getting a registry key

3. getting Nodes(keys) from the registry/??mlml

4. Getting/Changing Registry Keys

5. Getting a registry key

6. Getting a Registry key value

7. Getting registry key values

8. VB 4.0 and Getting Registry Sub Keys

9. REGISTRY How can I read a registry key?

10. find the specify Root key and Sub key from the registry

11. Getting ALL directories & sub directories

12. Registry Key - change (Default) key

 

 
Powered by phpBB® Forum Software