PC Review


Reply
Thread Tools Rate Thread

read dsn info from reg

 
 
mcnews
Guest
Posts: n/a
 
      3rd Mar 2011
how to read user dsn regkey created by DBEngine.RegisterDatabase?
need to retrieve so user can see it.
tia,
mcnewsxp
 
Reply With Quote
 
 
 
 
mcnewsxp
Guest
Posts: n/a
 
      3rd Mar 2011
i figured it out if anyone wants to know.


 
Reply With Quote
 
 
 
 
Access Developer
Guest
Posts: n/a
 
      4th Mar 2011
"mcnewsxp" <(E-Mail Removed)> wrote

> i figured it out if anyone wants to know.


Why don't you share it, just in case someone does? I'm sure it's
information that I might sometime find useful.

Larry Linson
Microsoft Office Access MVP


 
Reply With Quote
 
mcnewsxp
Guest
Posts: n/a
 
      4th Mar 2011
here's what i used. if you want to look up other HKEYs you'll need to find
the appropriate value.

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 RegQueryValueEx Lib "advapi32.dll" Alias
"RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As
Long, lpType As Long, ByVal lpData As String, _
lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
As Long

Public Const HKEY_CURRENT_USER = &H80000001
Public Const REG_BINARY As Long = 3
Public Const REG_DWORD As Long = 4

Public Function ReadRegistry(ByVal Group As Long, ByVal Section As String,
ByVal Key As String) As String

''''''use this somewhere appropriate in your app to get your value
' sVal = ReadRegistry(HKEY_CURRENT_USER, "Software\ODBC\ODBC.INI\PHINMS",
"Server")

Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long,
lValueLength As Long, sValue As String, td As Double
Dim TStr1 As String, TStr2 As String, i As Integer
On Error Resume Next
lResult = RegOpenKey(Group, Section, lKeyValue)
sValue = Space$(2048)
lValueLength = Len(sValue)
lResult = RegQueryValueEx(lKeyValue, Key, 0&, lDataTypeValue, sValue,
lValueLength)
If (lResult = 0) And (Err.Number = 0) Then
If lDataTypeValue = REG_DWORD Then
td = Asc(Mid$(sValue, 1, 1)) _
+ &H100& * Asc(Mid$(sValue, 2, 1)) + &H10000 *
Asc(Mid$(sValue, 3, 1)) + &H1000000 _
* CDbl(Asc(Mid$(sValue, 4, 1)))
sValue = Format$(td, "000")
End If
If lDataTypeValue = REG_BINARY Then
' Return a binary field as a hex string (2 chars per byte)
TStr2 = ""
For i = 1 To lValueLength
TStr1 = Hex(Asc(Mid(sValue, i, 1)))
If Len(TStr1) = 1 Then TStr1 = "0" & TStr1
TStr2 = TStr2 + TStr1
Next
sValue = TStr2
Else
sValue = Left$(sValue, lValueLength - 1)
End If
Else
sValue = "Not Found"
End If
lResult = RegCloseKey(lKeyValue)
ReadRegistry = sValue
End Function


 
Reply With Quote
 
Access Developer
Guest
Posts: n/a
 
      4th Mar 2011
Thanks for posting this for us. I've saved it off -- never can tell when you
might find it useful.

Larry Linson
Microsoft Office Access MVP

"mcnewsxp" <(E-Mail Removed)> wrote in message
news:ikqlvc$tgk$(E-Mail Removed)-september.org...
> here's what i used. if you want to look up other HKEYs you'll need to
> find the appropriate value.
>
> 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 RegQueryValueEx Lib "advapi32.dll" Alias
> "RegQueryValueExA" _
> (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As
> Long, lpType As Long, ByVal lpData As String, _
> lpcbData As Long) As Long
> Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As
> Long) As Long
>
> Public Const HKEY_CURRENT_USER = &H80000001
> Public Const REG_BINARY As Long = 3
> Public Const REG_DWORD As Long = 4
>
> Public Function ReadRegistry(ByVal Group As Long, ByVal Section As String,
> ByVal Key As String) As String
>
> ''''''use this somewhere appropriate in your app to get your value
> ' sVal = ReadRegistry(HKEY_CURRENT_USER, "Software\ODBC\ODBC.INI\PHINMS",
> "Server")
>
> Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long,
> lValueLength As Long, sValue As String, td As Double
> Dim TStr1 As String, TStr2 As String, i As Integer
> On Error Resume Next
> lResult = RegOpenKey(Group, Section, lKeyValue)
> sValue = Space$(2048)
> lValueLength = Len(sValue)
> lResult = RegQueryValueEx(lKeyValue, Key, 0&, lDataTypeValue, sValue,
> lValueLength)
> If (lResult = 0) And (Err.Number = 0) Then
> If lDataTypeValue = REG_DWORD Then
> td = Asc(Mid$(sValue, 1, 1)) _
> + &H100& * Asc(Mid$(sValue, 2, 1)) + &H10000 *
> Asc(Mid$(sValue, 3, 1)) + &H1000000 _
> * CDbl(Asc(Mid$(sValue, 4, 1)))
> sValue = Format$(td, "000")
> End If
> If lDataTypeValue = REG_BINARY Then
> ' Return a binary field as a hex string (2 chars per byte)
> TStr2 = ""
> For i = 1 To lValueLength
> TStr1 = Hex(Asc(Mid(sValue, i, 1)))
> If Len(TStr1) = 1 Then TStr1 = "0" & TStr1
> TStr2 = TStr2 + TStr1
> Next
> sValue = TStr2
> Else
> sValue = Left$(sValue, lValueLength - 1)
> End If
> Else
> sValue = "Not Found"
> End If
> lResult = RegCloseKey(lKeyValue)
> ReadRegistry = sValue
> End Function
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close ODBC Connection / DSN vs DSN-less Connection / Access 2k2 Front-End Greg Strong Microsoft Access 8 10th Jul 2006 06:32 AM
Changing Oracle connection from DSN to DSN-Less Red Microsoft Excel Programming 3 7th Oct 2005 10:42 AM
SQL.REQUEST linking Excel to Oracle - file dsn vs system dsn? D Microsoft Excel Programming 1 6th Aug 2004 09:42 PM
system.reg and windows.reg Bruce Roberson Windows XP Customization 5 30th Apr 2004 11:54 AM
Adding a TCP/IP port to the registry via reg.exe (REG ADD) Mike Kiser Microsoft Windows 2000 Registry Archive 0 14th Nov 2003 05:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:42 PM.