silver2kgt
Technical User
I am trying to add ODBC connections on remote PC's for performance logging. I can setup the perfmon settings fine, I just can't seem to get the registry keys and values to write to setup the ODBC connection. Maybe I've spent too much time looking at it and am missing something, but my code looks like everything I have found on the net and it doesn't want to work for me. I'm running XP Pro SP2.
PS - Set oReg = ... is all on one line.
PS - Set oReg = ... is all on one line.
Code:
Const HKEY_LOCAL_MACHINE = &H80000002
Dim DSN, DBName, Description, DrivekeyPath, DriverName, Server, oReg, keyPath, keyPath2, strName
strName = "."
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strName & "\root\default:StdRegProv")
DSN = "PerfMon"
DBName = "PerfMon"
Description = "ODBC Connection for Performance Monitoring"
DrivekeyPath = "%SystemRoot%/system32/sqlsrv32.dll"
DriverName = "SQL Server"
Server = "test"
keyPath = "\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\"
keyPath2 = "\SOFTWARE\ODBC\ODBC.INI\" & DSN
oReg.CreateKey HKEY_LOCAL_MACHINE, keyPath2
oReg.SetStringValue HKEY_LOCAL_MACHINE, keyPath, DSN, DriverName
oReg.SetStringValue HKEY_LOCAL_MACHINE, keyPath2, "Database", DBName
oReg.SetStringValue HKEY_LOCAL_MACHINE, keyPath2, "Description", Description
oReg.SetStringValue HKEY_LOCAL_MACHINE, keyPath2, "Driver", DrivekeyPath
oReg.SetStringValue HKEY_LOCAL_MACHINE, keyPath2, "Server", Server