Results 1 to 4 of 4

Thread: ODBC GetDataSourceList

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    6

    Question

    Is there a way to list data source names based on a specific driver? For example, how can I list only access data sources?

    Thanks

  2. #2
    Addicted Member eer3's Avatar
    Join Date
    Sep 2000
    Location
    Ca
    Posts
    165

    Try this

    'Place this code in a Form with a command button
    '*******************************

    Const HKEY_CLASSES_ROOT = &H80000000
    Const HKEY_CURRENT_CONFIG = &H80000005
    Const HKEY_CURRENT_USER = &H80000001
    Const HKEY_DYN_DATA = &H80000006
    Const HKEY_LOCAL_MACHINE = &H80000002
    Const HKEY_PERFORMANCE_DATA = &H80000004
    Const HKEY_USERS = &H80000003
    Const REG_BINARY = 3
    Const REG_DWORD = 4
    Const REG_DWORD_BIG_ENDIAN = 5
    Const REG_DWORD_LITTLE_ENDIAN = 4
    Const REG_EXPAND_SZ = 2
    Const REG_LINK = 6
    Const REG_MULTI_SZ = 7
    Const REG_NONE = 0
    Const REG_RESOURCE_LIST = 8
    Const REG_SZ = 1
    Const KEY_ENUMERATE_SUB_KEYS = &H8


    Private Sub CommandButton1_Click()
    Dim valuename As String ' name of the value being retrieved
    Dim valuelen As Long ' length of valuename
    Dim datatype As Long ' receives data type of value
    Dim data(0 To 254) As Byte ' 255-byte data buffer for read information
    Dim datalen As Long ' size of data buffer information
    Dim datastring As String ' will receive data converted to a string, if necessary
    Dim hkey As Long ' handle to the registry key to enumerate the values of
    Dim index As Long ' counter for the index of the value to enumerate
    Dim c As Long ' counter variable
    Dim retval As Long ' functions' return value

    ' Open the registry key to enumerate the values of.
    retval = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\odbc\odbc.ini\odbc data sources", _
    0, KEY_QUERY_VALUE, hkey)
    ' Check to see if an error occured.
    If retval <> 0 Then
    Debug.Print "Registry key could not be opened -- aborting."
    End ' abort the program
    End If

    ' Begin enumerating the values. Get each one, displaying its name. If it's a null-
    ' terminated string or binary data, display it. If not, say so.
    index = 0 ' initialize the counter
    While retval = 0 ' loop while successful
    ' Initialize the value name buffer.
    valuename = Space(255) ' 255-space buffer
    valuelen = 255 ' length of the string
    datalen = 255 ' size of data buffer
    ' Get the next value to be enumerated
    retval = RegEnumValue(hkey, index, valuename, valuelen, 0, datatype, data(0), datalen)
    If retval = 0 Then ' if successful, display information
    ' Extract the useful information from the value name buffer and display it.
    valuename = Left(valuename, valuelen)
    Debug.Print "Value Name: "; valuename
    ' Determine the data type of the value and display it.
    Select Case datatype
    Case REG_SZ ' null-terminated string
    ' Copy the information from the byte array into the string.
    ' We subtract one because we don't want the trailing null.
    datastring = Space(datalen - 1) ' make just enough room in the string
    CopyMemory ByVal datastring, data(0), datalen - 1 ' copy useful data
    Debug.Print " Data (string): "; datastring
    Case REG_BINARY ' binary data
    ' Display the hexadecimal values of each byte of data, separated by
    ' sapces. Use the datastring buffer to allow us to assure each byte
    ' is represented by a two-character string.
    Debug.Print " Data (binary):";
    For c = 0 To datalen - 1 ' loop through returned information
    datastring = Hex(data(c)) ' convert value into hex
    ' If needed, add leading zero(s).
    If Len(datastring) < 2 Then datastring = _
    String(2 - Len(datastring), "0") & datastring
    Debug.Print " "; datastring;
    Next c
    Debug.Print ' end the line
    Case Else ' a data type this example doesn't handle
    Debug.Print "This example doesn't know how to read that kind of data."
    End Select
    End If
    index = index + 1 ' increment the index counter
    Wend ' end the loop

    ' Close the registry key.
    retval = RegCloseKey(hkey)
    End Sub



    '*********************
    'Place this in a module


    Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
    End Type
    Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hkey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) 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 RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
    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
    Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, _
    Source As Any, ByVal Length As Long)
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const KEY_QUERY_VALUE = &H1
    Public Const REG_SZ = 1
    Public Const REG_BINARY = 3


    'That ought to get you close...Good luck!

  3. #3
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274

    Thumbs up HEY???

    We worked hard on this for you. Did it solve your problems? Hope so...cheers!

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    6

    Thumbs up Thank you so much

    Thanks. Works great!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width