Jump to content

Recommended Posts


Posted

I use a vbscript to add the DSN entries as part of the application install for our database application. You could use the same thing during unattend setup, or use .reg keys to achieve the same thing.

WSH SCRIPT FOR CREATING DSN ENTRIES IN FOR ODBC.

'ARRAY OF SETTINGS FOR EACH DSN ENTRY.
'EACH ELEMENT OF DSNLIST IS AN ARRAY OF SETTINGS FOR THAT DSN.
Dim DSNLIST (4)    
'CONSTANTS FOR REFERENCING THE DSN SETTINGS FROM THE DSNLIST ARRAY
Const DSNname    = 0
Const DSNdesc = 1
Const DSNServer = 2
Const DSN_DB = 3
'THE REGISTRY KEY FOR THE SYSTEM DSN SETTINGS
Const DSNkey = "HKLM\SOFTWARE\ODBC\ODBC.INI"

'POPULATE DSNLIST WITH DSN SETTINGS. TO ADD TO LIST, REMEMBER TO CHANGE THE DIM, AND FOR LOOP

DSNLIST(0) = Array("DSN name", "description", "Server", "database")
DSNLIST(1) = Array("DSN name", "description", "Server", "database")
DSNLIST(2) = Array("DSN name", "description", "Server", "database")
DSNLIST(3) = Array("DSN name", "description", "Server", "database")


'USE WSH TO WRITE DSN SETTINGS TO REGISTRY
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set WshShell = WScript.CreateObject("WScript.Shell")

'The following loop populates the DSN entries into the registry
For db = 0 to 3
WshShell.RegWrite DSNkey &"\" & DSNLIST(db) (DSNname) & "\Database", DSNLIST(db) (DSN_DB), "REG_SZ"
WshShell.RegWrite DSNkey &"\" & DSNLIST(db) (DSNname) & "\Description", DSNLIST(db) (DSNdesc), "REG_SZ"
'Next line turns off the ANSI padding
WshShell.RegWrite DSNkey &"\" & DSNLIST(db) (DSNname) & "\AnsiNPW", "No", "REG_SZ"
WshShell.RegWrite DSNkey &"\" & DSNLIST(db) (DSNname) & "\Driver", "C:\Windows\System32\SQLSRV32.dll", "REG_SZ"
WshShell.RegWrite DSNkey &"\" & DSNLIST(db) (DSNname) & "\Server", DSNLIST(db) (DSNServer), "REG_SZ"

'THE FOLLOWING REGISTRY KEY POPULATES THE ENTRY INTO THE ODBC CONTROL PANEL APPLET
WshShell.RegWrite DSNkey &"\ODBC Data Sources\" & DSNLIST(db) (DSNName), "SQL Server", "REG_SZ"

'UNCOMMENT WSCRIPT.ECHO TO DISPLAY ENTRIES AS THEY ARE WRITTEN (PROMPTS FOR OK).
'Wscript.Echo db, DSNLIST(db) (DSNname)
Next
Set WshSHell = Nothing

Just change the items in the arrays to match what your actual DSN settings are. If you need to add or change other settings, I would suggest making the settings manually and then inspecting the registry.

Posted

Set up your ODBC entries, then export the registry entries from HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI

And to force SQL Server ODBC to use TCP/IP port 1433 export relevant entries from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer

Posted

Nope, still have to test it. (I don't use it at home, it is just for testing at work. I'm trying to create a good working unattended installation over network before I suggest the idea to the 'boss'. They are verry, old fashioned here :s, It has to be perfect before they even consider looking at it. And zo I do al the testing after working hours too...)

edit: Boss went home this noon :-)

It works by just exporting the reg key, and then import it again. Have not tried the other script

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...