Page 1 of 1 1
Topic Options
#174372 - 2007-03-01 04:18 PM Update a SQL Database with Kixtart Startup Script
noobness Offline
Fresh Scripter

Registered: 2006-01-05
Posts: 32
I have a need for a database with the computer name, IP address, MAC address and domain of the computers in the building. I use a kixtart start up script and am thinking that a direction I could take would be to have the startup script update a database.

Previosly I was just linking to other databases that have the same information such as the Anti Virus central database (EPO, eTrust) but this is far from reliable data.

Any thoughts on if this would be a good idea, possible and direction I would take to accomplish this.

Thanks for any input in advance!

JD

Top
#174379 - 2007-03-01 09:00 PM Re: Update a SQL Database with Kixtart Startup Script [Re: noobness]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
There are a library of UDFs that can handle database transactions - look for DBConnOpen(), DBExecuteSQL(), and DBConnClose(), those should let you do what you're thinking of doing.
Top
#174395 - 2007-03-02 05:42 AM Re: Update a SQL Database with Kixtart Startup Script [Re: eriqjaffe]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
A startup script might not have network access or write access to a SQL database. It might be better to create a scheduled task running under a domain account that performs the logging a certain amount of time after startup.
_________________________
There are two types of vessels, submarines and targets.

Top
#174412 - 2007-03-02 04:17 PM Re: Update a SQL Database with Kixtart Startup Script [Re: Sealeopard]
noobness Offline
Fresh Scripter

Registered: 2006-01-05
Posts: 32
I found UDF that you where referring to and was playing around... I have not gottem them to write to the DB yet though.. Am I doing something wrong?


; Open connection to the SQL database
DBConnOpen("Driver={SQL Server};Server=SQLServerHostName;UID=someUser;PWD=withSomePassword`;Database=computers')
DBExecuteSQL($objConn,"INSERT INTO computers VALUES('@WKSTA','@DOMAIN','@ADDRESS','@IPADDRESS0')")
DBConnClose($objConn)

Function DBConnOpen($ConnDSN, optional $ConnTimeout, optional $CmdTimeout)
Dim $objConn, $adStateOpen
$adStateOpen=Val('&00000001')

If VarType($ConnTimeout)
$ConnTimeout=Val($ConnTimeout)
Else
$ConnTimeout=15
EndIf

If VarType($CmdTimeout)
$CmdTimeout=Val($CmdTimeout)
Else
$CmdTimeout=30
EndIf

$ConnDSN=Trim($ConnDSN)

If Not $ConnDSN
Exit 87
EndIf

$objConn = CreateObject("ADODB.Connection")

If @ERROR
Exit @ERROR
EndIf

$objConn.ConnectionTimeout = $ConnTimeout

If @ERROR
Exit @ERROR
EndIf

$objConn.CommandTimeout = $CmdTimeout

If @ERROR
Exit @ERROR
EndIf

$objConn.Open($ConnDSN)

If @ERROR
Exit @ERROR
EndIf

If Not $objConn.State=$adStateOpen
$objComm=''
$DBConnOpen=''
Exit @ERROR
EndIf

$DBConnOpen=$objConn
EndFunction

Function DBConnClose($objConn)
Dim $adStateOpen
$adStateOpen=Val('&00000001')
If VarType($objConn)=9
If $objConn.State = $adStateOpen
$objConn.Close()
If @ERROR
Exit @ERROR
EndIf
EndIf
$objConn=''
Else
Exit 87
EndIf

$DBConnClose=@ERROR
EndFunction

Function DBExecuteSQL ($objconn, $sql, OPTIONAL $cmdtype)
Dim $cmdcommand, $rsrecordset
Dim $adcmdunspecified, $adcmdtext, $adcmdtable, $adcmdstoredproc, $adcmdunknown, $adcmdfile, $adcmdtabledirect

$adcmdunspecified = -1
$adcmdtext = 1
$adcmdtable = 2
$adcmdstoredproc = 4
$adcmdunknown = 8
$adcmdfile = 256
$adcmdtabledirect = 512

If VarType($cmdtype)
$cmdtype=Val($cmdtype)
Else
$cmdtype=$adcmdtext
EndIf

If VarType($objconn) <> 9 Or $sql = ''
Exit 87
EndIf

$cmdcommand = CreateObject('ADODB.Command')
If @error
Exit @error
EndIf
$cmdcommand.activeconnection = $objconn
If @error
Exit @error
EndIf
$cmdcommand.commandtype = $cmdtype
If @error
Exit @error
EndIf
$cmdcommand.commandtext = $sql
If @error
Exit @error
EndIf

$rsrecordset=$cmdcommand.execute()
$cmdcommand=''
$rsrecordset=''
If @error
Exit @error
EndIf

$dbexecutesql=@error
EndFunction

Top
#174414 - 2007-03-02 04:19 PM Re: Update a SQL Database with Kixtart Startup Script [Re: Sealeopard]
noobness Offline
Fresh Scripter

Registered: 2006-01-05
Posts: 32
If I have to I could use the login script, or just put username and password credentials in the startup script and just make one account that only has access to that DB for security...

JD

Top
#174415 - 2007-03-02 04:22 PM Re: Update a SQL Database with Kixtart Startup Script [Re: noobness]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
GPO Startup scripts run under localsystem and as such have limited access beyond the local box.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#174430 - 2007-03-02 08:48 PM Re: Update a SQL Database with Kixtart Startup Script [Re: Les]
noobness Offline
Fresh Scripter

Registered: 2006-01-05
Posts: 32
Correct, however the UDF had a place to specify credentials if needed to the SQL server... Either way, I like this idea and could do this during the login script opposed to the startup script if needed.

I cant get it to update the database even when I execute the script when logged in.

Any ideas where my syntax in the above script is off? The bottom functions are all pulled from the UDF

JD

Top
#174439 - 2007-03-03 05:52 AM Re: Update a SQL Database with Kixtart Startup Script [Re: noobness]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
 Code:
DBConnOpen("Driver={SQL Server};Server=SQLServerHostName;UID=someUser;PWD=withSomePassword`;Database=computers')
DBExecuteSQL($objConn,"INSERT INTO computers VALUES('@WKSTA','@DOMAIN','@ADDRESS','@IPADDRESS0')")
DBConnClose($objConn)

contains non-matching string terminators.

A cleaner approach would be
 Code:
$sql = "INSERT INTO computers VALUES('"+@WKSTA+"','"+@DOMAIN+"','"+@ADDRESS+"','+"@IPADDRESS0+"')"
DBConnOpen('Driver={SQL Server};Server=SQLServerHostName;UID=someUser;PWD=withSomePassword;Database=computers')
DBExecuteSQL($objConn,$sql)
DBConnClose($objConn)


Still the startup script might not have sufficient rigths to access entwork resources, thus even if the script works while logged in it would not work as a startup script.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

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

Generated in 0.187 seconds in which 0.16 seconds were spent on a total of 13 queries. Zlib compression enabled.

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