Page 1 of 1 1
Topic Options
#62803 - 2002-02-05 11:01 AM Sample script for creating an ODBC Connection
MasterOfDesaster Offline
Fresh Scripter

Registered: 2002-01-23
Posts: 21
Loc: Munich, Germany
Hi,

perhaps someone need a script like this....

This script creates or make changes to a SYSTEM-DNS SQL-Server ODBC Connection...

code:
  
;Create a System-DNS ODBC Entry in the Registry
;M.Szekely
;

;Variables

$regODBC="HKLM\Software\ODBC\ODBC.ini"
$regDBSName="ZMDB"
$regDBSDescription="Zentrales Management"
$regDBSDriver="%systemroot%\system32\SQLSRV32.dll"
$regDBSUser="%Username%"
$regDBSServer="SM009"


;Write the values to the registry

if not keyexist("$regODBC\$regDBSName")
$RC=addkey("$regODBC\$regDBSName")
$RC=writevalue("$regODBC\ODBC DATA Sources","$regDBSName","SQL Server","REG_SZ")
endif


$RC=writevalue("$regODBC\$regDBSName","Database",$regDBSName,"REG_SZ")
$RC=writevalue("$regODBC\$regDBSName","Description",$regDBSDescription,"REG_SZ")
$RC=writevalue("$regODBC\$regDBSName","Driver",$regDBSDriver,"REG_SZ")
$RC=writevalue("$regODBC\$regDBSName","LastUser",$regDBSUser,"REG_SZ")
$RC=writevalue("$regODBC\$regDBSName","Server",$regDBSServer,"REG_SZ")
$RC=writevalue("$regODBC\$regDBSName","Trusted_Connection","Yes","REG_SZ")


[ 05 February 2002: Message edited by: MasterOfDesaster ]

[ 06 February 2002: Message edited by: MasterOfDesaster ]

_________________________
Greetings,

Michael

Top
#62804 - 2002-02-05 11:49 AM Re: Sample script for creating an ODBC Connection
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Neat indeed !

you got my vote for being productive for the community since you participate here !

Jochen

btw. Where do you come from in Germany ?

_________________________



Top
#62805 - 2002-02-05 01:59 PM Re: Sample script for creating an ODBC Connection
MasterOfDesaster Offline
Fresh Scripter

Registered: 2002-01-23
Posts: 21
Loc: Munich, Germany
Thanks,

i'm from Munich...

_________________________
Greetings,

Michael

Top
#62806 - 2002-02-05 03:46 PM Re: Sample script for creating an ODBC Connection
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Master,

Your code looks a lot better than mine.

code:

$HKLMS = 'HKEY_LOCAL_MACHINE\SOFTWARE'

; This adds in the Datatrac ODBC Connection for the Control Panel
ATATRAC
;Check for the existence of the ODBC Data Sources For the Control Panel
If 0 <> EXISTKEY($HKLMS+"\ODBC\ODBC.INI\ODBC Data Sources")
$ = ADDKEY($HKLMS+"\ODBC\ODBC.INI\ODBC Data Sources")
ENDIF
If 0 = ExistKey($HKLMS+"\ODBC\ODBC.INI\DataTrac")
;IF THEY HAVE THE ODBC CONNECTION
RETURN
ELSE
;ADD A DATASOURCE FOR THE CONTROL PANEL
$ = WRITEVALUE($HKLMS+"\ODBC\ODBC.INI\ODBC Data Sources","DataTrac","Microsoft Visual FoxPro Driver","REG_SZ")
;SET THE REGISTRY PATH STRING
$ODBCPATH = $HKLMS+"\ODBC\ODBC.INI\DataTrac"
;ASSUME THE STRING DOESN'T EXIST
$ = ADDKEY($ODBCPATH)
;NOW, WRITE SOME VALUES FOR THIS ODBC CONNECTION
$ = WRITEVALUE($ODBCPATH,"Driver","%windir%\SYSTEM32\VFPODBC.dll","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"SourceDB","R:\Datatrac\Tables\datatrac.DBC","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"Description","","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"SourceType","DBC","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"BackgroundFetch","No","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"Exclusive","No","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"Null","Yes","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"Deleted","Yes","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"Collate","Machine","REG_SZ")
$ = WRITEVALUE($ODBCPATH,"SetNoCountOn","No","REG_SZ")
RETURN
ENDIF


Thanks!

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#62807 - 2002-02-05 09:15 PM Re: Sample script for creating an ODBC Connection
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
Yes, very good one indeed!!
Got my vote too

Did you get a look to see if a possibility exist to skip the need of a reboot ?

_________________________
? getobject(Kixtart.org.Signature)

Top
#62808 - 2002-02-05 10:42 PM Re: Sample script for creating an ODBC Connection
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Alex,

I have not had that problem with the ODBC Connects.. It is an instant change and the user can get right in.

Thanks!

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#62809 - 2002-02-06 12:29 AM Re: Sample script for creating an ODBC Connection
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
Kent,
I didn't try it for the moment, but i wanted to know about it, as MoD stated :
;Remark: The PC must be restarted to activate the changes

Anyway, if it's not needed it will be really great !!! I really need some cold water on my head!!
Currently finishing one blockbuster and i'll go on something with this stuff.
About the current script in building state, Kent, did you ever dream of creating 50+ users in ten clicks or less (assuming your boss fill an Excel worksheet before with the new user to add (full name and groups, that's all)) ?

Hint : while playing with an AD script, I mistakely created some users on the NT4 domain using WinNT:// Active Directory provider. This little baby was only installed on my NT4 station while logged on the same domain, but not on the servers. You'll certainly see the rest, as in fact the AD methods and properties used for are working on any NT domain through WinNT:// provider

[ 06 February 2002: Message edited by: Alex.H ]

_________________________
? getobject(Kixtart.org.Signature)

Top
#62810 - 2002-02-06 01:08 AM Re: Sample script for creating an ODBC Connection
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Alex,

You mean something like...

(Lonkero - Don't go nuts on me as these are not KIX Scripts!! )

Thanks!

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#62811 - 2002-02-06 01:16 AM Re: Sample script for creating an ODBC Connection
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
Kent,

You know what ? I should really take my hands and dig into this one. Never take a look but i'll really do it (well, sooner )
Seems I'm just trying to rebuild the wheel.

Oh well, this one will be for kixtart, so yes Lonkero, go nuts at me

[ 06 February 2002: Message edited by: Alex.H ]

_________________________
? getobject(Kixtart.org.Signature)

Top
#62812 - 2002-02-06 09:47 AM Re: Sample script for creating an ODBC Connection
MasterOfDesaster Offline
Fresh Scripter

Registered: 2002-01-23
Posts: 21
Loc: Munich, Germany
Hi,

i was wrong, there is no reboot needed to activate the ODBC Settings. Sorry for the wrong message.

I've thested the Script only on NT4, but it should work on W2K and XP also.

_________________________
Greetings,

Michael

Top
#62813 - 2002-07-31 07:23 PM Re: Sample script for creating an ODBC Connection
FTPMonster Offline
Fresh Scripter

Registered: 2002-05-30
Posts: 16
Can I just go on record as saying you just made my life SO easy? [Smile]
Thank you!

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.071 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org