Private Sub Form_Load()
Dim hKey As Long
Dim value As String
Dim length As Long
Dim value_type As Long
Dim key_num As Long
Dim subkey_name As String
Dim subkey_length As Long
Dim file_time As FILETIME
' Open HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI.
If RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\ODBC\ODBC.INI", _
0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS _
Then
MsgBox "Error opening key."
Exit Sub
End If
MSFlexGrid1.Rows = 1
MSFlexGrid1.Cols = 3
MSFlexGrid1.TextMatrix(0, 0) = "Name"
MSFlexGrid1.TextMatrix(0, 1) = "Driver"
MSFlexGrid1.TextMatrix(0, 2) = "Description"
' Enumerate the subkeys, skipping "ODBC Data Sources."
key_num = 0
Do
' Get the subkey's information.
subkey_length = 256
subkey_name = Space$(subkey_length)
If RegEnumKeyEx( _
hKey, key_num, subkey_name, subkey_length, _
ByVal 0&, ByVal 0&, 0, file_time) _
<> ERROR_SUCCESS Then Exit Do
subkey_name = Left$(subkey_name, subkey_length)
' Display the information.
If subkey_name <> "ODBC Data Sources" Then
MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 0) _
= subkey_name
MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 1) _
= _
GetKeyValue(HKEY_LOCAL_MACHINE, _
"Software\ODBC\ODBC.INI\" & _
subkey_name, _
"Driver")
MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 2) _
= _
GetKeyValue(HKEY_LOCAL_MACHINE, _
"Software\ODBC\ODBC.INI\" & _
subkey_name, _
"Description")
End If
key_num = key_num + 1
Loop
' Close the key.
If RegCloseKey(hKey) <> ERROR_SUCCESS Then
MsgBox "Error closing key."
End If
SizeColumns MSFlexGrid1
End Sub
' Return a subkey's value.
Private Function GetKeyValue(ByVal key_root As Long, ByVal _
key_name As String, ByVal subkey_name As String) As _
String
Dim hKey As Long
Dim value As String
Dim length As Long
Dim value_type As Long
Dim key_num As Long
Dim file_time As FILETIME
' Open the key.
If RegOpenKeyEx(key_root, key_name, _
0&, KEY_QUERY_VALUE, hKey) <> ERROR_SUCCESS _
Then Exit Function
' Get the subkey's value.
length = 256
value = Space$(length)
If RegQueryValueEx(hKey, subkey_name, _
0&, value_type, ByVal value, length) _
<> ERROR_SUCCESS _
Then Exit Function
' Remove the trailing null character.
GetKeyValue = Left$(value, length - 1)
' Close the key.
RegCloseKey hKey
End Function
|