你的函数用错了
Option ExplicitPrivate Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const HKEY_DYN_DATA = &H80000006Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private Const KEY_ALL_ACCESS = ((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))
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))Private Const REG_SZ = 1                         ' Unicode nul terminated string
Private Const REG_EXPAND_SZ = 2                  ' Unicode nul terminated string
Private Const REG_MULTI_SZ = 7                   ' Multiple Unicode strings
Private Const REG_DWORD = 4                      ' 32-bit number
Private Const REG_DWORD_BIG_ENDIAN = 5           ' 32-bit numberPrivate Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
End TypePrivate 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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition 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 RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As LongPrivate Sub Devide(ByVal Key As String, ByRef cKey As Long, ByRef sKey As String)
    
    Select Case Left(Key, InStr(Key, "\") - 1)
    
        Case "HKEY_CLASSES_ROOT"
            cKey = HKEY_CLASSES_ROOT
            
        Case "HKEY_CURRENT_USER"
            cKey = HKEY_CURRENT_USER
            
        Case "HKEY_LOCAL_MACHINE"
            cKey = HKEY_LOCAL_MACHINE
            
        Case "HKEY_USERS"
            cKey = HKEY_USERS
            
        Case "HKEY_PERFORMANCE_DATA"
            cKey = HKEY_PERFORMANCE_DATA
            
        Case "HKEY_CURRENT_CONFIG"
            cKey = HKEY_CURRENT_CONFIG
            
        Case "HKEY_DYN_DATA"
            cKey = HKEY_DYN_DATA
            
    End Select
    
    sKey = Mid(Key, InStr(Key, "\") + 1)
    
End SubPublic Function GetRegDefaultValue(ByVal Key As String) As String
    
    Dim ret As Long, cKey As Long, sKey As String, lenS As Long, S As String
    
    Devide Key, cKey, sKey
    lenS = 80
    S = String(lenS, Chr(0))
    ret = RegQueryValue(cKey, sKey, S, lenS)
    
    If ret = 0 Then
    
        S = Left(S, InStr(S, Chr(0)) - 1)
        
        If S = " " Then
        
            S = "(未设置数值)"
            
        End If
        
    End If
    
    GetRegDefaultValue = S
    
End FunctionPublic Function GetRegValue(ByVal Key As String, ByVal Name As String) As Variant
    
    Dim ret As Long, cKey As Long, sKey As String, hKey As Long, lenData As Long, typeData As Long
    
    Devide Key, cKey, sKey
    ret = RegOpenKeyEx(cKey, sKey, 0, KEY_READ, hKey)
    If ret <> 0 Then Exit Function
    ret = RegQueryValueEx(hKey, Name, 0, typeData, ByVal vbNullString, lenData)
    
    If ret <> 0 Then
        
        RegCloseKey hKey
        Exit Function
        
    End If
    
    Select Case typeData
        
        Case REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ
            
            Dim S As String
            
            S = String(lenData, Chr(0))
            RegQueryValueEx hKey, Name, 0, typeData, ByVal S, lenData
            
            If typeData = REG_SZ Then
            
                S = Left(S, InStr(S, Chr(0)) - 1)
                GetRegValue = S
                
            End If
            
        Case REG_DWORD, REG_DWORD_BIG_ENDIAN
            Dim L As Long
            
            RegQueryValueEx hKey, Name, 0, typeData, L, lenData
            GetRegValue = L
            
    End Select
    
    RegCloseKey hKeyEnd Function

解决方案 »

  1.   

    To egg629(蛋) 老兄,你粘得一大堆过干嘛,我是要用RegEnumValue这个函数检举一个子项下面的所有数据
      

  2.   

    RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
      

  3.   

    这是完整的例子,看不看随你:Const HKEY_CURRENT_CONFIG = &H80000005
    Const HKEY_LOCAL_MACHINE = &H80000002
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
    Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
    Private Sub Form_Paint()
        Dim hKey As Long, Cnt As Long, sSave As String
        'Clear the form
        Me.Cls
        Me.Print "RegEnumKeyEx"
        'Open a registry key
        RegOpenKey HKEY_LOCAL_MACHINE, "Enum", hKey
        Do
            'Create a buffer
            sSave = String(255, 0)
            'Enumerate the keys
            If RegEnumKeyEx(hKey, Cnt, sSave, 255, 0, vbNullString, ByVal 0&, ByVal 0&) <> 0 Then Exit Do
            'Print the result to the form
            Me.Print StripTerminator(sSave)
            Cnt = Cnt + 1
        Loop
        'Close the registry key
        RegCloseKey hKey
        Me.Print vbCrLf + "RegEnumValue:"
        'Open a new key
        RegOpenKey HKEY_CURRENT_CONFIG, "Display\Fonts", hKey
        Cnt = 0
        Do
            'Create a buffer
            sSave = String(255, 0)
            'enumerate the values
            If RegEnumValue(hKey, Cnt, sSave, 255, 0, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then Exit Do
            'pritn the results to the form
            Me.Print StripTerminator(sSave)
            Cnt = Cnt + 1
        Loop
        'Close the registry
        RegCloseKey hKey
    End Sub
    'This function is used to stripoff all the unnecessary chr$(0)'s
    Private Function StripTerminator(sInput As String) As String
        Dim ZeroPos As Integer
        'Search the first chr$(0)
        ZeroPos = InStr(1, sInput, vbNullChar)
        If ZeroPos > 0 Then
            StripTerminator = Left$(sInput, ZeroPos - 1)
        Else
            StripTerminator = sInput
        End If
    End Function
      

  4.   

    dim j_hwnd,lngname as long
    dim strname as string
    dim t(1000) as byte
    strname=space(255)
    call regopenkey_(hkey_local_machine,"software\microsoft\windows\currentversion",j_hwnd)
    call RegEnumValue(j_hwnd,0,strname,255,0,0,t(0),1000)
    试一下
      

  5.   

    没人来UP吗?UP也有分哦,呵呵
      

  6.   

    VB操作注册表:
    http://www.sqreg.com/file/vb/reg_01.htm
    http://www.sqreg.com/file/vb/reg_02.htm
    http://www.sqreg.com/file/vb/reg_03.htm
    http://www.sqreg.com/file/vb/reg_04.htm
    http://www.sqreg.com/file/vb/reg_05.htm
    http://www.sqreg.com/file/vb/reg_06.htm
    http://www.sqreg.com/file/vb/reg_07.htm