Я остановился на примере, приведенном ниже. Но вот беда: я не знаю имен ключей. Т.е. мне нужно как-то организовать цикл по всем ключам из заданного раздела и читать имена ключей и их значения. А как? Или этот пример мне вообще не поможет?
Вот, собственно, сам пример:
- Код: Выделить всё
Private Const REG_SZ As Long = &H1&
Private Const REG_BINARY As Long = &H3&
Private Const HKEY_CLASSES_ROOT As Long = &H80000000
Private Const HKEY_CURRENT_CONFIG As Long = &H80000005
Private Const HKEY_CURRENT_USER As Long = &H80000001
Private Const HKEY_DYN_DATA As Long = &H80000006
Private Const HKEY_LOCAL_MACHINE As Long = &H80000002
Private Const HKEY_PERF_ROOT As Long = HKEY_LOCAL_MACHINE
Private Const HKEY_PERFORMANCE_DATA As Long = &H80000004
Private Const HKEY_USERS As Long = &H80000003
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 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
Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
If lResult = 0 Then
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, Chr$(0))
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
End If
ElseIf lValueType = REG_BINARY Then
Dim strData As Integer
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = strData
End If
End If
End If
End Function
Function GetString(hKey As Long, strPath As String, strValue As String)
Dim Ret
RegOpenKey hKey, strPath, Ret
GetString = RegQueryStringValue(Ret, strValue)
RegCloseKey Ret
End Function
Использование:
- Код: Выделить всё
RetVal$ = GetString(HKEY_CURRENT_USER, "SOFTWARE\Prg1", "Key1")