通过下面函数可以读取注册表某节点下的某个参数值:
    RegOpenKey hKey, strPath, Ret
    GetString = RegQueryStringValue(Ret, strValue)
但是我想枚举某个节点下的所有节点名称,怎么做?比如:
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\下有很多子节点,怎样枚举出来?
我想要的是如果在该节点下发现"myopt"这个节点,则msgbox "找到了!"

解决方案 »

  1.   

    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 RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByRef phkResult As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Const HKEY_LOCAL_MACHINE As Long = &H80000002Private Sub Command1_Click()
    Dim hKey As Long, ret As Long, Name As String, Idx As Long
    Dim tempName As StringList1.Clear
    RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE", hKey
    Idx = 0
    Name = String(256, Chr(0))
    Do
        ret = RegEnumKey(hKey, Idx, Name, Len(Name))
        If ret = 0 Then
            tempName = Left(Name, InStr(Name, Chr(0)) - 1)
            List1.AddItem tempName
            If Trim(LCase(tempName)) = "myopt" Then Debug.Print "找到了myopt"
            Idx = Idx + 1
        End If
    Loop Until ret <> 0RegCloseKey hKey
    End Sub
      

  2.   

    \\RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE", hKey\\上面这句代码改为
    RegOpenKey HKEY_LOCAL_MACHINE, "ControlSet001", hKey'改为你的节点