| Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (Byval hKey As Long, Byval lpSubKey As String, phkResult As Long) As Long |
| Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval Reserved As Long, Byval dwType As Long, lpData As Any, Byval cbData As Long) As Long |
| Declare Function RegCloseKey Lib "advapi32.dll" (Byval hKey As Long) As Long |
| |
| |
| . |
| . |
| . |
| sDSN_ZUD = "DSN_ZUD" |
| Call CreateDSNString (sDSN_ZUD) |
| . |
| . |
| . |
| |
| Private Sub CreateDSNString (DataSourceName As String) |
| |
| Const REG_SZ = 1 |
| Const HKEY_LOCAL_MACHINE = &H80000002 |
| |
| Dim DatabaseName As String |
| Dim Description As String |
| Dim DriverPath As String |
| Dim DriverName As String |
| Dim LastUser As String |
| Dim Regional As String |
| Dim Server As String |
| Dim Password As String |
| Dim TrustedConnection As String |
| |
| Dim lResult As Long |
| Dim hKeyHandle As Long |
| |
| |
| DatabaseName = "<SQLDatenbank>" |
| Description = "Yes I can" |
| DriverPath = "C:\WINDOWS\system32\SQLSRV32.dll" |
| |
| |
| Server = "<Servername>" |
| DriverName = "SQL Server" |
| TrustedConnection = "Yes" |
| |
| |
| lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & DataSourceName, hKeyHandle) |
| |
| |
| lResult = RegSetValueEx(hKeyHandle, "Database", 0&, REG_SZ, Byval DatabaseName, Len(DatabaseName)) |
| lResult = RegSetValueEx(hKeyHandle, "Description", 0&, REG_SZ, Byval Description, Len(Description)) |
| lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, Byval DriverPath, Len(DriverPath)) |
| |
| lResult = RegSetValueEx(hKeyHandle, "Server", 0&, REG_SZ, Byval Server, Len(Server)) |
| lResult = RegSetValueEx(hKeyHandle, "Trusted_Connection", 0&, REG_SZ, Byval TrustedConnection, Len(TrustedConnection)) |
| |
| |
| lResult = RegCloseKey(hKeyHandle) |
| |
| |
| lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle) |
| |
| |
| lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, REG_SZ, Byval DriverName, Len(DriverName)) |
| |
| |
| lResult = RegCloseKey(hKeyHandle) |