怎么把注册表中某项中所有的“字符串值”都列出来?

解决方案 »

  1.   

    【函数】
    RegEnumValue【操作系统】
    Win9X:Yes
    WinNT:Yes【声明】
    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【说明】  枚举指定项的值 【返回值】  Long,零(ERROR_SUCCESS)表示成功。其他任何值都代表一个错误代码 【其它】
    【参数表】
      hKey -----------  Long,一个已打开项的句柄,或者指定一个标准项名  dwIndex --------  Long,欲获取值的索引。注意第一个值的索引编号为零  lpValueName ----  String,用于装载位于指定索引处值名的一个缓冲区  lpcbValueName --  Long,用于装载lpValueName缓冲区长度的一个变量。一旦返回,它会设为实际载入缓冲区的字符数量  lpReserved -----  Long,未用;设为零  lpType ---------  Long,用于装载值的类型代码的变量  lpData ---------  Byte,用于装载值数据的一个缓冲区  lpcbData -------  Long,用于装载lpData缓冲区长度的一个变量。一旦返回,它会设为实际载入缓冲区的字符数量
      

  2.   

    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