With VBA, find the version of the MySQL ODBC driver installed in Windows

后端 未结 3 671
独厮守ぢ
独厮守ぢ 2021-01-12 10:49

Using Visual Basic for Applications, how can I find out which version of the MySQL ODBC driver is installed in Windows on a user\'s machine?

I have

3条回答
  •  再見小時候
    2021-01-12 11:36

    You can find it in the registry under

    HKEY_LOCAL_MACHINE\SOFTWARE\
        ODBC\ODBCINST.INI\
        ODBC Drivers\MySQL ODBC 3.51 Driver
    
    
     HKEY_LOCAL_MACHINE\SOFTWARE\
        ODBC\ODBCINST.INI\
        ODBC Drivers\MySQL ODBC 5.1 Driver
    

    Using the info found here, you can get at it using the below code (I tested it in Access 97)

    Private Sub Command0_Click()    
        If RegKeyExists("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\
                                     ODBC Drivers\MySQL ODBC 3.51 Driver") Then
            MsgBox "3.51"
        ElseIf RegKeyExists("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\
                                     ODBC Drivers\MySQL ODBC 5.1 Driver") Then
            MsgBox "5.1"
        Else
            MsgBox "None"
        End If
    End Sub
    
    
    'returns True if the registry key i_RegKey was found
    'and False if not
    Function RegKeyExists(i_RegKey As String) As Boolean
        Dim myWS As Object
    
        On Error GoTo ErrorHandler
        'access Windows scripting
        Set myWS = CreateObject("WScript.Shell")
        'try to read the registry key
        myWS.RegRead i_RegKey
        'key was found
        RegKeyExists = True
        Exit Function
    
    ErrorHandler:
      'key was not found
      RegKeyExists = False
    End Function
    

提交回复
热议问题