1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const ERROR_NO_MORE_ITEMS = 259&
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public 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
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
'
' Lecture d'une chaine dans base de registre
'
Function LitChaine(ByVal hKey As Long, stChemin As String, stCle As String) As String
Dim temp As Long
Dim result As Long
Dim tampon As String
Dim TailleTampon As Long
If RegOpenKey(hKey, stChemin, result) = 0 Then
TailleTampon = 255
tampon = Space(TailleTampon)
temp = RegQueryValueEx(result, stCle, 0, 0, ByVal tampon, TailleTampon)
LitChaine = Left$(tampon, TailleTampon - 1)
RegCloseKey hKey
End If
End Function
'
'Fonction ListeSousClefs
'
Function ListeSousClefs(ByVal hKey As Long, stChemin As String) As Collection
Dim result As Long
Dim tampon As String
Dim lIndex As Long
Dim Ret As Long
Dim t As New Collection
If RegOpenKey(hKey, stChemin, result) = 0 Then
Ret = 255
tampon = Space(Ret)
While RegEnumKeyEx(result, lIndex, tampon, Ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS
t.Add Left$(tampon, Ret)
lIndex = lIndex + 1
Ret = 255
tampon = Space(Ret)
Wend
Set ListeSousClefs = t
RegCloseKey hKey
Else
MsgBox "Erreur ouverture " & stChemin
End If
End Function |
Partager