I'm trying to find out if there is a way that I could via login script or from the cmd prompt I could configure DSN for my pcs. There is a 3rd party application that I need to configure DSN for on each machine.
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: Space
Get a copy of REGSHOT and then on a clean system run the first snapshot of the system, then create your DSN, then take the second snapshot of the system.
Then do a compare and:
You should see these keys modified (and maybe a few more depending on options selected)
HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\DB-Lib HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources HKLM\SOFTWARE\ODBC\ODBC.INI
You can then easily write some Admin code to remotely add this entry to any system you have Admin rights on.
If you need further assistance please let us know.
OK, I was finally able to run the Regshot.exe. I 1st removed the system dsn entry ran regshot, then added the dsn and ran regshot again:
Here is outcome for Values added: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\SmartClinic: "SQL Server" HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SmartClinic\Driver: "C:\WINDOWS\system32\SQLSRV32.dll" HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SmartClinic\Description: "SmartClinic" HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SmartClinic\Server: "MEDICALSERVER" HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SmartClinic\LastUser: "sa"
There was a whole bunch of other stuff, but it did not seem to be related to the dsn connection.
I tried to run the WriteValue (Copy and pasted the strings above and it didn't add the entry)
What am I doing wrong? and am i missing some registry entries?
If worst comes to worst, I will copy and paste the whole log from regshot.
I think I figured it out, I will have to try it at there site tonight to test it out.
In my script, I was adding the I was using the wrong syntax for adding a key. I then read in my book that I don't have to use the "ADDKEY" function, I could simply just use the "writevalue" function and it will add the key as well as the value. Once I straightend everything out with my test script in my testing enviroment,upon login it added the .txt ODBC connection.
Here is a portion of my script that I am using for my live enviroment:
Alright, I added the comma to my code and it worked.
NTDOC, I will try out your code as well. Questions though? Because this is going in a login script, should I add anything else in the code so that it doesn't run everytime a user logs in?
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: Space
Well there are a couple things.
1. Yes you should run code normally to check if it's been run before or not. 2. Unless your users are local administrators on their systems (not a best practice) then they won't be able to create these entries in the HKLM part of the registry.
Here is code for what you asked, though if you really need to do this and your users don't have admin rights then you'll need to run code to accomplish this as an admin script remotely.
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: Space
Yeah, but from my experience most people don't seem to want to use a USER DSN as it can be modified by the user and is more difficult to maintain consistency.
You could easily modify your UDF to support both local and remote for Admins.
1. Yes you should run code normally to check if it's been run before or not. 2. Unless your users are local administrators on their systems (not a best practice) then they won't be able to create these entries in the HKLM part of the registry.
Here is code for what you asked, though if you really need to do this and your users don't have admin rights then you'll need to run code to accomplish this as an admin script remotely.