Get a list of the ODBC drivers installed
Posted by admin - Apr 1, 2008 ADODB, Articles, Dani Vainstein, QTips 0 0 Views : 398 Receive Updates For This Category
Article Tools
- Print this page
- Add Comment
- Send to Friend
- Last Updated on :
Jul 16, 2011
The registry, is the upstairs closet of the operating system: if you’re willing to look, you can find almost anything in the registry. That’s where can be found the list of installed ODBC drivers, in HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers.
Const HKLM = &H80000002
Set reg = GetObject( "winmgmts:\\.\root\default:StdRegProv" )
keyPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
reg.EnumValues HKLM, keyPath, valueNamesArr, valueTypeArr
For i = 0 to UBound( valueNamesArr )
reg.GetStringValue HKLM, keyPath, valueNamesArr( i ), valueStr
Print valueNamesArr( i ) & " --> " & valueStr
Next
We begin by defining a constant named HKLM and setting the value to &H80000002; we’ll use this constant to indicate that we want to work with the HKLM registry hive. We connect to the WMI service and to the standard registry provider (root\default:StdRegProv), then use this line of code to assign the registry path within HKLM to the variable keyPath
keyPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
As it turns out, the installed ODBC drivers are stored as individual registry values within this registry key, something like this:
Therefore, to retrieve a collection of all these registry values we need to call the EnumValues method, a method which automatically grabs all the values within a specified key:
reg.EnumValues HKLM, keyPath, valueNamesArr, valueTypeArr
When we call EnumValues we need to supply two in parameters and two out parameters. “In parameters” are values we supply to the method; in this script we pass the constant HKLM and the variable keyPath. Taken together, these parameters tell the script which registry key we’re working with
“Out parameters” represent information that the method provides to us. To get this information all we have to do is provide a pair of variable names. In our script, the variable valueNamesArr will end up holding an array of all the registry value names found in SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers; the variable valueTypesArr will hold an array of data types for each of these registry values. this particular parameter included, only because it’s required.
After calling EnumValues all the individual registry value names will be stored (as an array) in the variable valueNamesArr. To access those values we need to set up a For-Next loop that runs from 0 to the last item (the upper bound or UBound) in the array. That’s what this line of code does:
For i = 0 to UBound( valueNamesArr )
To actually get the values that have been assigned to those registry entries we need to call the GetStringValue method, something we do here:
reg.GetStringValue HKLM, keyPath, valueNamesArr( i ), valueStr
As you can see, we pass GetStringValue four parameters:
HKLM, representing the registry hive.
keyPath, the registry path within HKLM.
valueName, representing the individual registry value.
valueStr, an out parameter which will store the value of the registry entry.
After that we can simply use this line of code to print back the name of the registry value and the value assigned to it:
Print valueNamesArr( i ) & " --> " & valueStr


