VBS/VB ODBC Creation Script

How to create a basic SQL AD authentication ODBC connection (2003/2003 64)

This could easily be adapted to scripted deployments and will work on server 2003 / 2003 64.

Before starting, the easiest way to know exactly what you need to add is to export
HKEY_LOCAL_MACHINESOFTWAREODBCODBC.INI%odbc folder% and
HKEY_LOCAL_MACHINESOFTWAREODBCODBC.INIODBC Data Sources%data source name%
These exports will give you the keys needing to be added.

Below is what has worked for me, however additional keys/changes can be added to suit:

On Error Resume Next

Dim Registry
Set Registry = WScript.CreateObject(“WScript.Shell”)
Set objShell = WScript.CreatedObject (“WScript.Shell”)

‘Setup ODBC
DataSourceName = “******”
Server = “******
DriverName = “******
DatabaseName = “******
WindowsAuthentication = True
DriverPath = “C:WindowsSystemSQLSRV32.dll”
REG_KEY_PATH = “HKLMSOFTWAREODBCODBC.INI” & DataSourceName

‘Create the DSN only if it doesn’t already exist.
Result = Registry.RegRead (REG_KEY_PATH & “Server”)
If Result = “” Then
Registry.RegWrite REG_KEY_PATH & “DataBase”,DatabaseName,”REG_SZ”
Registry.RegWrite REG_KEY_PATH & “LastUser”,LastUser,”REG_SZ”
Registry.RegWrite REG_KEY_PATH & “Server”,Server,”REG_SZ”
Registry.RegWrite REG_KEY_PATH & “Driver”,DriverPath,”REG_SZ”
If WindowsAuthentication = True Then
Registry.RegWrite REG_KEY_PATH & “Trusted_Connection”,”Yes”,”REG_SZ”
End If
‘ This key is required for the DSN to appear in the ODBC Control Panel
REG_KEY_PATH = “HKLMSOFTWAREODBCODBC.INIODBC Data Sources” & DataSourceName
Registry.RegWrite REG_KEY_PATH,DriverName,”REG_SZ”
End If
Set Registry = Nothing