How to create System DSN in Windows Vista

I would like to know how to create System DSN in Windows Vista?Sample coding i have its works for Windows XP.
Thanks
[125 byte] By [the_magicien] at [2007-11-20 10:52:01]
# 1 Re: How to create System DSN in Windows Vista
Post your code. I don't have Vista here, but have used it.
dglienna at 2007-11-9 19:34:18 >
# 2 Re: How to create System DSN in Windows Vista
this my code

' Registry API functions
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal _
hwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String, _
ByVal lpszAttributes As String) As Long
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" _
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, ByRef phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, _
ByRef lpcbData As Long) As Long

Const REG_SZ = 1
Const KEY_ALL_ACCESS = &H2003F
Const HKEY_CURRENT_USER = &H80000001

Public Const ODBC_ADD_DSN = 1 ' Add data source
Public Const ODBC_REMOVE_DSN = 3 ' Delete data source

Sub MakeDSN(ByVal sDSN As String, ByVal sDriver As String, _
ByVal sDBFile As String, ByVal lAction As Long)

Dim sAttributes As String
Dim sDBQ As String
Dim lngRet As Long

Dim hKey As Long
Dim regValue As String
Dim valueType As Long

' query the Registry to check whether the DSN is already installed
' open the key
If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\ODBC\ODBC.INI\" & sDSN, 0, _
KEY_ALL_ACCESS, hKey) = 0 Then
' zero means no error => Retrieve value of "DBQ" key
regValue = String$(1024, 0)
' Allocate Variable Space
If RegQueryValueEx(hKey, "DBQ", 0, valueType, regValue, _
Len(regValue)) = 0 Then
' zero means OK, so we can retrieve the value
If valueType = REG_SZ Then
sDBQ = Left$(regValue, InStr(regValue, vbNullChar) - 1)
End If
End If
' close the key
RegCloseKey hKey
End If

' Perform the action only if we're adding a DSN that doesn't exist
' or removing and existing DSN
If (sDBQ = "" And lAction = ODBC_ADD_DSN) Or (sDBQ <> "" And lAction = _
ODBC_REMOVE_DSN) Then

' check that the file actually exists
If Len(Dir$(sDBFile)) = 0 Then
MsgBox "Database file doesn't exist!", vbOKOnly + vbCritical
Exit Sub
End If
sAttributes = "DSN=" & sDSN & vbNullChar & "DBQ=" & sDBFile & vbNullChar
lngRet = SQLConfigDataSource(0&, lAction, sDriver, sAttributes)
End If
End Sub

private sub cmdcreate1()
sDriver = "Microsoft Access Driver (*.mdb)"
sName = "DSN Creation Test"
sFile = App.Path & "\MyDatabase.mdb"
MakeDSN sName, sDriver, sFile, ODBC_ADD_DSN

end sub
the_magicien at 2007-11-9 19:35:24 >
# 3 Re: How to create System DSN in Windows Vista
Does it work if you make a .reg file, and click on it? Right-click doesn't give the Install/Merge message, but double clicking installs it. Did it last night.

here's a reg file that worked.

The famous IE7 Timeoue fiasco. Sets it back to 8 minutes!

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ReceiveTimeout"=dword:00075300
dglienna at 2007-11-9 19:36:20 >
# 4 Re: How to create System DSN in Windows Vista
sorry i did not understand
the_magicien at 2007-11-9 19:37:21 >
# 5 Re: How to create System DSN in Windows Vista
Try to create a reg file and manually add it. (You can create the key using Control Panel, and then export it.)

I think it may be in a different spot, or there is a permission problem.
dglienna at 2007-11-9 19:38:20 >