Se connecter / S'enregistrer
Votre question

[resolue][visual Basic] comment lire dans la base de registre

Tags :
  • software
  • Programmation
Dernière réponse : dans Programmation
19 Juin 2006 14:50:11

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

Autres pages sur : resolue visual basic lire base registre

a c 145 L Programmation
19 Juin 2006 16:56:37

il existe en vb.net la classe registry pour accéder à la base de registre, mais je ne suis pas sûr que ce soit possible en vb "normal"
20 Juin 2006 15:41:40

Ah oué c bien embetant sa!!
j'ai trouver quelques code comme :

Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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 RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) 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
Public 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 Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long


Mais je ne sais pas les utiliser...
Contenus similaires
20 Juin 2006 20:20:45

  1. Dim VBS As New WshShell
  2.  
  3. Function LireReg(chemin As String) As String
  4. On Error Resume Next
  5. LireReg = VBS.RegRead(chemin)
  6. End Function


Utilisation

  1. dim test as string
  2. test = LireReg("Chemin\de\ta\cle")


PS : Il faut inclure une référence mais je ne sais plus laquelle
21 Juin 2006 06:30:09

Install le sdk de .Net Framework 2.0 et plus besoin de passer par les dll de windows. ca donne un truc du genre :

  1. Imports System
  2. Imports Microsoft.Win32
  3. Imports Microsoft.VisualBasic
  4.  
  5. Dim Rk As RegistryKey = Registry.CurrentUser
  6. Dim Path As String
  7. Dim Rsk As RegistryKey
  8. Dim Valeur As Object
  9.  
  10. Path = chemin de la cle
  11.  
  12. if (Rsk = Rk.OpenSubKey(Path)) then
  13. Valeur = Rsk.GetValue("NomDeLaDonnée")
  14. endif
21 Juin 2006 08:11:00

Je peut pas utilisé le vb.net je suis sur miscrosoft visual basic fourni par CorelDraw 12 c'est une macro pour CorelDraw
21 Juin 2006 09:40:51

C'est bon j'ai trouver :

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
Tom's guide dans le monde
  • Allemagne
  • Italie
  • Irlande
  • Royaume Uni
  • Etats Unis
Suivre Tom's Guide
Inscrivez-vous à la Newsletter
  • ajouter à twitter
  • ajouter à facebook
  • ajouter un flux RSS