[visual Basic] comment lire dans la base de registre

comment lire dans la base de registre [visual Basic] - VB/VBA/VBS - Programmation

Marsh Posté le 19-06-2006 à 14:50:58    

Salut voila je voudrais récupérer une donnée dans la base de registre (je veu la chemin d'acces d'une application)
Voila ou se trouve la donnée que je cherche( "HKEY_LOCAL_MACHINE\SOFTWARE\Corel\Setup\CorelDRAW Graphics Suite 12", "Destination" ) je voudrais connaitre le code pour recupérer donnée contenu dans "Destination".
merci

Reply

Marsh Posté le 19-06-2006 à 14:50:58   

Reply

Marsh Posté le 19-06-2006 à 14:55:23    

C'est  écrit dans la msdn:
msdn.microsoft.com


---------------
Töp of the plöp
Reply

Marsh Posté le 19-06-2006 à 15:11:59    

J'ai essay donc avec la methode GetSetting mais elle marche que pour les programmes se trouvant dans "HKEY_CURRENT_USER\Software\VB and VBA Program Settings" alors sa me va pas moi il me faut aller dans "HKEY_LOCAL_MACHINE\SOFTWARE\Corel\Setup\CorelDRAW Graphics Suite 12"
comment faire??

Reply

Marsh Posté le 19-06-2006 à 17:06:50    

Reply

Marsh Posté le 20-06-2006 à 15:42:21    

J'ai ete voir ton site mais g pas bien comprit comme le code fonctionnner...

Reply

Marsh Posté le 20-06-2006 à 15:49:41    

Que n'as-tu pas compris ?

Reply

Marsh Posté le 20-06-2006 à 15:53:38    

Spoiler :

la langue française


Message édité par _darkalt3_ le 20-06-2006 à 15:53:52
Reply

Marsh Posté le 20-06-2006 à 15:56:31    

' Open the key.
    If RegOpenKeyEx(root, key_name, _
        0&, KEY_QUERY_VALUE, hKey) <> ERROR_SUCCESS _
    Then
        MsgBox "Error opening key."
        Exit Function
    End If
 
je n'arrive pas a uliser ce code pour extraire la valeur de la donnée que j'ai besoin

Reply

Marsh Posté le 20-06-2006 à 16:08:44    

Ouep je vois.
L'exemple ne donne pas la déclaration des API windows qui permettent de lire la BDR, ni les constantes courantes à utiliser. Pas terrible.
Voici les déclarations à faire dans un module  (je donne plus que nécessaire là)

Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
 
Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
 
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
 
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
 
Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
 
Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
 
Declare Function RegCloseKey Lib "advapi32.dll" Alias "RegCloseKey" (ByVal hKey As Long) As Long
 
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
 
Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
 
Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
 
Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long


Déclare aussi les constantes suivantes, c'est la valeur à passer en paramètre root je pense :

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003


Message édité par tegu le 20-06-2006 à 16:09:04
Reply

Marsh Posté le 20-06-2006 à 16:20:24    

il y a un bouton DOWNLOAD en bas .... puis tu dézippes et compiles
tu ne vois qu'un extrait de code ....


Message édité par kiki29 le 20-06-2006 à 16:22:58
Reply

Marsh Posté le 20-06-2006 à 16:20:24   

Reply

Marsh Posté le 20-06-2006 à 16:28:17    

oki et dans :
 
RegOpenKeyEx(root, key_name, _  
        0&, KEY_QUERY_VALUE, hKey)
 
dans root je met : HKEY_LOCAL_MACHINE
dans key_name :  SOFTWARE\Corel\Setup\CorelDRAW Graphics Suite 12
Si g bien comprit ?!!

Reply

Marsh Posté le 20-06-2006 à 16:33:18    

>kiki29: moi je vois pas les images des pages web où je suis, donc le bouton pfffuit :)
 
Oui ptitnico22 tu as compris, sinon suis le conseil de kiki29 et récupère le module tout prêt; moi j'ai peut-être fait des adaptations de typage des APIs (c'est vieux) et ça pourrait te poser des pb.


Message édité par tegu le 20-06-2006 à 16:33:37
Reply

Marsh Posté le 21-06-2006 à 09:43:38    

Oki merci donc j'ai mit sa et sa marche tres bien :
 
Option Explicit
 
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
 
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, 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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
 
Private Const ERROR_SUCCESS = 0&
 
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private Const KEY_ALL_ACCESS = _
    ((STANDARD_RIGHTS_ALL Or _
    KEY_QUERY_VALUE Or _
    KEY_SET_VALUE Or _
    KEY_CREATE_SUB_KEY Or _
    KEY_ENUMERATE_SUB_KEYS Or _
    KEY_NOTIFY Or KEY_CREATE_LINK) And _
    (Not SYNCHRONIZE))
 
 
 
' Return a registry key value.
 
Function GetRegKeyValue(ByVal root As Long, ByVal key_name As String, ByVal subkey_name As String) As String
Dim hKey As Long
Dim value As String
Dim length As Long
Dim value_type As Long
 
key_name = "SOFTWARE\Corel\Setup\CorelDRAW Graphics Suite 12"
subkey_name = "Destination"
 
    ' Open the key.
    If RegOpenKeyEx(HKEY_LOCAL_MACHINE, key_name, _
        0&, KEY_QUERY_VALUE, hKey) <> ERROR_SUCCESS _
    Then
        MsgBox "Error opening key."
        Exit Function
    End If
 
    ' Get the subkey's size.
    If RegQueryValueEx(hKey, subkey_name, _
        0&, value_type, ByVal 0&, length) _
            <> ERROR_SUCCESS _
    Then
        MsgBox "Error getting subkey length."
    End If
 
    ' Get the subkey's value.
    value = Space$(length)
    If RegQueryValueEx(hKey, subkey_name, _
        0&, value_type, ByVal value, length) _
            <> ERROR_SUCCESS _
    Then
        MsgBox "Error getting subkey value."
    Else
        ' Remove the trailing null character.
        GetRegKeyValue = Left$(value, length - 1)
    End If
 
    ' Close the key.
    If RegCloseKey(hKey) <> ERROR_SUCCESS Then
        MsgBox "Error closing key."
    End If
     
   
End Function
 
 Sub main()
 
Dim key_name As String
Dim subkey_name As String
Dim lblValue As String
 
key_name = "SOFTWARE\Corel\Setup\CorelDRAW Graphics Suite 12"
subkey_name = "Destination"
 
lblValue = GetRegKeyValue(HKEY_USERS, key_name, subkey_name)
 
MsgBox (lblValue)
End Sub
 
 
merci a tous!!

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed