odrezet
Messages postés4Date d'inscriptionlundi 21 février 2005StatutMembreDernière intervention 7 août 2009
-
15 nov. 2007 à 22:52
odrezet
Messages postés4Date d'inscriptionlundi 21 février 2005StatutMembreDernière intervention 7 août 2009
-
16 nov. 2007 à 08:09
Bonjour,
Débutant, je sèche depuis quelques jours sur un truc tout bête. Je fais un bout de code pour obtenir des informations msde et sql express 2005 par la base de registre; le but principal, étant d'obtenir une liste des instances installées et leurs versions.
Mon code fonctionne; j'ai la liste des valeurs. Mais quand je récupère leur contenu, c'est caractère par caractère ! Par exemple, "MSSQL.1" est collecté en "M", puis "S" et ainsi de suite ...
Je pose le code ci-dessous; si vous aviez un début de piste ... Sûr que c'est une broutille de débutant !
Merci d'avance !
OptionExplicitOn
Imports System
Imports System.IO
Imports System.Text
PublicClass DetectMSDE
'Déclaration des fonctions de l'API
PrivateDeclareFunction RegOpenKeyEx Lib"advapi32.dll" _
Alias"RegOpenKeyExA" _
(ByVal hKey AsInteger, _
ByVal lpSubKey AsString, _
ByVal ulOptions AsInteger, _
ByVal samDesired AsInteger, _
ByVal phkResult AsInteger)AsInteger
PrivateDeclareFunction RegEnumValue Lib"advapi32.dll" _
Alias"RegEnumValueA" _
(ByVal hKey AsLong, _
ByVal dwIndex AsLong, _
ByVal lpValueName AsString, _
ByVal lpcbValueName AsLong, _
ByVal lpReserved AsLong, _
ByVal lpType AsLong, _
ByVal lpData AsString, _
ByVal lpcbData AsLong)AsLong
PrivateDeclareFunction RegCloseKey Lib"advapi32.dll" _
(ByVal hKey AsLong)AsLong
'Déclaration des constantes de l'API
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const ERROR_SUCCESS = 0&
Const SYNCHRONIZE = &H100000
Const STANDARD_RIGHTS_READ = &H20000
Const STANDARD_RIGHTS_WRITE = &H20000
Const STANDARD_RIGHTS_EXECUTE = &H20000
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const STANDARD_RIGHTS_ALL = &H1F0000
Const KEY_ALL_ACCESS = &H3F
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_READ = ((STANDARD_RIGHTS_ALL Or _
KEY_QUERY_VALUE Or _
KEY_ENUMERATE_SUB_KEYS Or _
KEY_NOTIFY)And(Not SYNCHRONIZE))
Const REG_DWORD = 4
Const REG_BINARY = 3
Const REG_SZ = 1
'Déclenchement de la détection (lecture du registre)
PrivateSub TestDirV9(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button4.Click
Dim lngKeyHandle As IntPtr
Dim lngResult AsLong
Dim lngCurIdx AsLong
Dim strValue AsString
Dim lngValueLen AsLong
Dim lngData AsLong
Dim lngDataLen AsLong
Dim strResult AsString
' Ouverture de la clé concernée
lngResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", _
0&, _
KEY_READ, _
lngKeyHandle)
If lngResult <> ERROR_SUCCESS Then
MsgBox("Impossible d'ouvrir la clé.")
ExitSub
EndIf