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
If you want to avoid handling versions on a case by case basis you can iterate through the key values, eg..
This function is designed to enumerate through the regkeys for ODBC drivers and just check for the existance of mysql somewhere, if not it will warn the user then take them to the download page, and remind them to get the right version for their architecture (32/64)
Public Function CheckMySQL()
Dim arrEntryNames()
Dim arrValueTypes()
Dim rPath As String
rPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
Call EnumerateRegEntries(rPath, arrEntryNames, arrValueTypes)
If Not IsEmpty(arrEntryNames) Then
For Each strAsk In arrEntryNames
If (InStr(strAsk, "MySQL")) Then
strFound = strFound & strAsk & ", "
End If
Next
End If
If (Len(strFound) = 0) Then
#If Win64 Then
MsgBox "You need MySQL Driver *64 bit* - Press OK to get it!"
#Else
MsgBox "You need MySQL Driver *32 bit* - Press OK to get it!"
#End If
ActiveWorkbook.FollowHyperlink Address:="http://goo.gl/vbm6g", NewWindow:=True
CheckMySQL = False
Else
CheckMySQL = True
End If
End Function
And you'll need this to enumerate the reg keys (for more on this see http://technet.microsoft.com/en-us/library/ee176771.aspx):
Public Sub EnumerateRegEntries(strKeyPath, arrEntryNames, arrValueTypes)
Const HKEY_CLASSES_ROOT = &H80000000&
Const HKEY_CURRENT_USER = &H80000001&
Const HKEY_LOCAL_MACHINE = &H80000002&
Const HKEY_USERS = &H80000003&
Const HKEY_CURRENT_CONFIG = &H80000005&
Dim objReg As Object
Dim strComputer As String
strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
objReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrEntryNames, arrValueTypes
End Sub