Lire les chaines contenues dans une clés du registre

Teradonis Messages postés 15 Date d'inscription dimanche 5 janvier 2003 Statut Membre Dernière intervention 30 septembre 2005 - 2 mars 2003 à 14:11
cs_babouche Messages postés 61 Date d'inscription jeudi 30 mai 2002 Statut Membre Dernière intervention 2 mai 2007 - 2 mars 2003 à 17:17
Je C ke la kestion a déjà été posé plusieurs fois mais comment peut on lire les chaines ou les clés contenues dans une clés du registre!!!
J'aimerais une réponse précise et enfin un truc ki marche svp!!!!

1 réponse

cs_babouche Messages postés 61 Date d'inscription jeudi 30 mai 2002 Statut Membre Dernière intervention 2 mai 2007
2 mars 2003 à 17:17
' bon bah regarde ca (je sais plus ou je l'ai pompé, suremment dans les sources mais je l'ai largemment modifié...)
' pour t'en servir, c'est pas dure,
' "SaveKey" crée une clée
' "GetString" lit une donnée chaine
' "SaveString" écrit une donnée chaine
' "GetDword" lit une donné numérique
' "SaveDword" écrit une donné numérique
' "DeleteKey" éfface une clée
' "DeleteValue" éfface une entrée et sa valeur
' "Run" écrit dans Software\Microsoft\Windows\CurrentVersion\Run pour mettre des programmes au démarrage

' bon voila, j'éspère que ca marchera (c'est testé WinXP seulement mais les APIs devraient marcher sur tout système > Win98...)

' SI QUELQU'UN UTILISE CE SCRIPT ET RENCONTRE DES ERREURS, JE LUI DEMANDE DE ME LES COMMUNIQUER (m_babou2000@yahoo.fr).

Option Explicit

Enum HKEYs
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
End Enum
Enum RunKeys
HKEY_CURRENT_USER_Run = &H80000001
HKEY_LOCAL_MACHINE_Run = &H80000002
End Enum
Enum Options
Create_All = 0
Send_Error = 1
End Enum
Public Const ERROR_SUCCESS = 0&
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Public Const REG_SZ = 1
Public Const REG_DWORD = 4
Dim r

Public Sub SaveKey(Hkey As HKEYs, strPath As String)
On Error GoTo errr
Dim keyhand&
r = RegCreateKey(Hkey, strPath, keyhand&)
r = RegCloseKey(keyhand&)
Exit Sub
errr:
Call MsgBox("Can't find advapi32.dll", vbCritical, "Error !!!")
End
End Sub

Public Function GetString(Hkey As HKEYs, strPath As String, strValue As String)
On Error GoTo errr
Dim keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
Dim lValueType As Long
r = RegOpenKey(Hkey, strPath, keyhand)
lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
GetString = Left$(strBuf, intZeroPos - 1)
Else
GetString = strBuf
End If
End If
End If
Exit Function
errr:
Call MsgBox("Can't find advapi32.dll", vbCritical, "Error !!!")
End
End Function

Public Sub SaveString(Hkey As HKEYs, strPath As String, strValue As String, strData As String)
On Error GoTo errr
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
r = RegCloseKey(keyhand)
Exit Sub
errr:
Call MsgBox("Can't find advapi32.dll", vbCritical, "Error !!!")
End
End Sub

Function GetDword(ByVal Hkey As HKEYs, ByVal strPath As String, ByVal strValueName As String) As Long
On Error GoTo errr
Dim lResult As Long
Dim lValueType As Long
Dim lBuf As Long
Dim lDataBufSize As Long
Dim r As Long
Dim keyhand As Long
r = RegOpenKey(Hkey, strPath, keyhand)
lDataBufSize = 4
lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_DWORD Then
GetDword = lBuf
End If
End If
r = RegCloseKey(keyhand)
Exit Function
errr:
Call MsgBox("Can't find advapi32.dll", vbCritical, "Error !!!")
End
End Function

Function SaveDword(ByVal Hkey As HKEYs, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
On Error GoTo errr
Dim lResult As Long
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
r = RegCloseKey(keyhand)
Exit Function
errr:
Call MsgBox("Can't find advapi32.dll", vbCritical, "Error !!!")
End
End Function

Public Function DeleteKey(ByVal Hkey As HKEYs, ByVal strKey As String)
On Error GoTo errr
Dim r As Long
r = RegDeleteKey(Hkey, strKey)
Exit Function
errr:
Call MsgBox("Can't find advapi32.dll", vbCritical, "Error !!!")
End
End Function

Public Function DeleteValue(ByVal Hkey As HKEYs, ByVal strPath As String, ByVal strValue As String)
On Error GoTo errr
Dim keyhand As Long
Dim r As Long
r = RegOpenKey(Hkey, strPath, keyhand)
r = RegDeleteValue(keyhand, strValue)
r = RegCloseKey(keyhand)
Exit Function
errr:
Call MsgBox("Can't find advapi32.dll", vbCritical, "Error !!!")
End
End Function

Public Sub Run(Hkey As RunKeys, strValue As String, strData As String)
Call SaveString(Hkey, "Software\Microsoft\Windows\CurrentVersion\Run", strValue, strData)
End Sub
0
Rejoignez-nous