Groups | Blog | Home
all groups > sql server new users > april 2007 >

sql server new users : Creating Data Sources (ODBC) via code



CreateWindow
4/29/2007 12:00:00 AM
Hi John,

This looks good:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1110.mspx

For remote PC's you will need to use a UNC path and run the script with an
account that is also valid administrative account on your remote PC's.

CreateWindow
http://justldap.com




[quoted text, click to view]

John
4/29/2007 3:39:10 AM
Hi

I need to create a User DSN based on SQL Server driver under Data Sources
(ODBC). As I need to do it on multiple PCs, is there a script or another
automated way to do this quickly?

Thanks

Regards

John
4/29/2007 4:48:05 AM
Hi

Many Thanks. Looks good. Just one thing, how do I add the username and
password for SQL Server authentication?

Thanks again

Regards


Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
strValueName = "My SQL Server"
strValue = "SQL Server"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"

objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"

strValueName = "Database"
strValue = "My Database"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "Driver"
strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "Server"
strValue = "111.111.111.111"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "Trusted_Connection"
strValue = "No"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue



[quoted text, click to view]

AddThis Social Bookmark Button