Thread: DSN Listing
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Michael Rekas[_2_] Michael Rekas[_2_] is offline
external usenet poster
 
Posts: 12
Default DSN Listing

Thanks. I appreciate your persistence.

Your code returns all default and Microsoft SQL databases.

I searched the registry and found that the Pervasive.SQL DSNs (and for
that matter the Microsoft SQl DSNs) are stored in the same key under
HKEY_LOCAL_MACHINE.

I added "Const HKEY_LOCAL_MACHINE = &H80000002" to the declarations (a
good guess as I really do not understand your code!).

I also changed HKEY_CIRRENT_USER to HKEY_LOCAL_MACHINE in the Sub and
it gives me exactly what I want.

Absolutely thrilled. Thanks for the help.

Regards

Michael.



On Fri, 25 Feb 2005 14:45:34 -0000, "RB Smissaert"
wrote:

OK, this code will do it:


Option Explicit
Const ERROR_NO_MORE_ITEMS = 259&
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_USERS = &H80000003
Private Declare Function RegCloseKey _
Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegOpenKey _
Lib "advapi32.dll" _
Alias "RegOpenKeyA" (ByVal hKey As Long, _
ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegEnumKeyEx _
Lib "advapi32.dll" Alias _
"RegEnumKeyExA" (ByVal hKey As Long, _
ByVal dwIndex As Long, _
ByVal lpName As String, _
lpcbName As Long, _
ByVal lpReserved As Long, _
ByVal lpClass As String, _
lpcbClass As Long, _
lpftLastWriteTime As Any) As Long

Sub ShowExternalDataSources()

Dim hKey As Long
Dim Cnt As Long
Dim sName As String
Dim sData As String
Dim Ret As Long
Dim RetData As Long
Const BUFFER_SIZE As Long = 255

Ret = BUFFER_SIZE

If RegOpenKey(HKEY_CURRENT_USER, _
"Software\ODBC\ODBC.INI", _
hKey) = 0 Then
sName = Space(BUFFER_SIZE)
While RegEnumKeyEx(hKey, _
Cnt, _
sName, _
Ret, _
ByVal 0&, _
vbNullString, _
ByVal 0&, _
ByVal 0&) < ERROR_NO_MORE_ITEMS
Cnt = Cnt + 1
Cells(Cnt, 1) = Left$(sName, Ret)
sName = Space(BUFFER_SIZE)
Ret = BUFFER_SIZE
Wend
'close the registry key
RegCloseKey hKey
Else
MsgBox "Error while calling RegOpenKey", , ""
End If

End Sub


RBS


"Michael Rekas" wrote in message
.. .
Hi there

Does anybody have code that will bring in a list of external data
sources i.e. the list that appears when you click Data, Get external
Data, New Database Query.

Thanks

Michael