Guru | Voici une fonction récuppérée a l'époque chez Microsoft...
Code :
- Public Function GetKeyValue( _
- KeyRoot As Long, _
- KeyName As String, _
- SubKeyRef As String, _
- ByRef KeyVal As String _
- ) As Boolean
- Dim i As Long
- Dim rc As Long
- Dim hKey As Long
- Dim hDepth As Long
- Dim KeyValType As Long
- Dim tmpVal As String
- Dim KeyValSize As Long
- rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, hKey)
- If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError
- tmpVal = String$(1024, 0)
- KeyValSize = 1024
- rc = RegQueryValueEx(hKey, SubKeyRef, 0, KeyValType, tmpVal, KeyValSize)
- If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError
- If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then
- tmpVal = Left(tmpVal, KeyValSize - 1)
- Else
- tmpVal = Left(tmpVal, KeyValSize)
- End If
- Select Case KeyValType
- Case REG_SZ
- KeyVal = tmpVal
- Case rEG_DWORD
- For i = Len(tmpVal) To 1 Step - 1
- KeyVal = KeyVal + Hex(Asc(Mid(tmpVal, i, 1)))
- Next
- KeyVal = Format$("&h" + KeyVal)
- End Select
- GetKeyValue = True
- rc = RegCloseKey(hKey)
- Exit Function
- GetKeyError:
- KeyVal = ""
- GetKeyValue = False
- rc = RegCloseKey(hKey)
- End Function
|
|