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 55
| '
' http://msdn.microsoft.com/en-us/library/aa393664(VS.85).aspx
'
Private Function ObjetRegistre() As Object
Set ObjetRegistre = GetObject("winmgmts:\\.\root\default:StdRegProv")
End Function
Public Function LireRegistre(TopKey As Long, SubKey As String, ValueName As String) As Variant
Dim varValeur As Variant
With ObjetRegistre
.GetStringValue TopKey, SubKey, ValueName, varValeur
End With
LireRegistre = varValeur
End Function
Public Function ExisteRegistre(TopKey As Long, SubKey As String, ValueName As String) As Boolean
ExisteRegistre = Not IsNull(LireRegistre(TopKey, SubKey, ValueName))
End Function
Public Function EffaceRegistre(TopKey As Long, SubKey As String, ValueName As String)
With ObjetRegistre
.DeleteValue TopKey, SubKey, ValueName
End With
End Function
Public Sub EcrireRegistre(TopKey As Long, SubKey As String, ValueName As String, prmvarValeur As Variant)
Dim var
With ObjetRegistre
var = .CreateKey(TopKey, SubKey)
If var <> 0 Then
Stop
End If
var = .SetStringValue(TopKey, SubKey & "\", ValueName, prmvarValeur)
If var <> 0 Then
Stop
End If
End With
End Sub
Public Function EnumèreRegistre(ByVal lTopKey As Long, sSubKey As String) As Collection
Dim varSousClés As Variant
Dim varClé As Variant
Set EnumèreRegistre = New Collection
With ObjetRegistre
.EnumKey lTopKey, sSubKey, varSousClés
End With
If Not IsNull(varSousClés) Then
For Each varClé In varSousClés
EnumèreRegistre.Add (varClé)
Next
End If
End Function |
Partager