#206832 - 2013-02-28 05:57 PM
Re: ODBC check using Kix
[Re: Thrasonic]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
If you are simply wanting to detect the presence of an ODBC connection, the registry is a pretty easy method.
$odbcName = "MS Access Database" ; SET THIS TO THE NAME OF THE ODBC YOU WANT TO CHECK FOR
$logfile = "\\share\path\to\log\ODBC_LOG.txt" ; SET THIS TO THE PATH OF THE LOG FILE YOU WOULD TO WRITE TO
If KeyExist("HKCU\Software\ODBC\ODBC.INI\"+$odbcName)
$nul = RedirectOutput($logfile)
? @Date+" - "+@Time+" - "+$odbcname+" Found on "+@WkSta+" under user "+@UserID ; CAN MODIFY THIS TO WHAT EVER YOU WOULD LIKE TO BE LOGGED
$nul = RedirectOutput("")
Endif
|
Top
|
|
|
|
#206890 - 2013-03-08 09:17 PM
Re: ODBC check using Kix
[Re: NTDOC]
|
Thrasonic
Fresh Scripter
Registered: 2011-08-15
Posts: 26
Loc: GA
|
Thanks for all the replies and ideas. Okay, here's the script edited for my environment:
$odbcName = "tess_live_readonly" ; SET THIS TO THE NAME OF THE ODBC YOU WANT TO CHECK FOR
$logfile = "C:\ODBC_LOG.txt" ; SET THIS TO THE PATH OF THE LOG FILE YOU WOULD TO WRITE TO
REM $logfile = "\\fileserver\goldshare\ODBC_LOG.txt" ; SET THIS TO THE PATH OF THE LOG FILE YOU WOULD TO WRITE TO
If KeyExist("HKCU\Software\ODBC\ODBC.INI\" + $odbcName) Or KeyExist("HKLM\Software\ODBC\ODBC.INI\" + $odbcName)
$nul = RedirectOutput($logfile)
? @Date+" - "+@Time+" - "+$odbcname+" Found on "+@WkSta+" under user "+@UserID ; CAN MODIFY THIS TO WHAT EVER YOU WOULD LIKE TO BE LOGGED
$nul = RedirectOutput("")
Endif
I changed the location of the log file to my local C: because it wasn't working pointing to the fileserver share, but the problem is that it doesn't seem to be working going to my C: drive either. I do have an ODBC connection named tess_live_readonly in the HKLM key but a log file isn't being written. I don't see a problem in the script so what might be the issue?
Edited by Mart (2013-03-11 09:13 AM) Edit Reason: Please use code tags when posting code.
|
Top
|
|
|
|
#206891 - 2013-03-08 10:05 PM
Re: ODBC check using Kix
[Re: Thrasonic]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Well for starters....REM is not a kix command. If you want remark a line out, simply add a semi-colon in front of it. Other than that, are you sure you have rights to create a file in the root of C:\. Try the below and see if it creates the file.
$odbcName = "tess_live_readonly" ; SET THIS TO THE NAME OF THE ODBC YOU WANT TO CHECK FOR
$logfile = "C:\ODBC_LOG.txt" ; SET THIS TO THE PATH OF THE LOG FILE YOU WOULD TO WRITE TO
; $logfile = "\\fileserver\goldshare\ODBC_LOG.txt" ; SET THIS TO THE PATH OF THE LOG FILE YOU WOULD TO WRITE TO
If KeyExist("HKCU\Software\ODBC\ODBC.INI\" + $odbcName) Or KeyExist("HKLM\Software\ODBC\ODBC.INI\" + $odbcName)
$nul = RedirectOutput($logfile)
@Date+" - "+@Time+" - "+$odbcname+" Found on "+@WkSta+" under user "+@UserID ?
$nul = RedirectOutput("")
Else
$nul = RedirectOutput($logfile)
@Date+" - "+@Time+" - "+$odbcname+" NOT Found on "+@WkSta+" under user "+@UserID ?
$nul = RedirectOutput("")
Endif
When I simply change the REM to a semi-colon and changed the odbc name to check for.it seemed to work just fine for me.
Edited by ShaneEP (2013-03-08 10:06 PM)
|
Top
|
|
|
|
#206895 - 2013-03-11 06:08 PM
Re: ODBC check using Kix
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Here is the log file loading method...
$odbcName = "tess_live_readonly"
$logfile = "C:\ODBC_LOG.txt"
If KeyExist("HKCU\Software\ODBC\ODBC.INI\" + $odbcName) OR KeyExist("HKLM\Software\ODBC\ODBC.INI\" + $odbcName)
For Each $line in LoadFile($logfile, @CRLF)
If InStr($line,@WkSta) AND InStr($line,@UserID)
$logged=1
Endif
Next
If Not $logged
$nul = RedirectOutput($logfile)
@Date+" - "+@Time+" - "+$odbcname+" Found on "+@WkSta+" under user "+@UserID ?
$nul = RedirectOutput("")
Endif
Endif
Function loadfile($file, optional $array, $Uni)
DIM $fso,$f,$fs
If $uni $uni = $uni-3 Else $uni = -2 Endif
If Not $uni $uni = -2 Endif
$fso = CreateObject("Scripting.FileSystemObject")
$f = $fso.GetFile($file)
If @ERROR Exit 2 EndIf
$fs = $f.OpenAsTextStream(1,$uni)
If Not $array
$loadfile = $fs.Read($f.size)
Else
$loadfile = Split($fs.Read($f.size),$array)
Endif
Exit @ERROR
EndFunction
|
Top
|
|
|
|
#206896 - 2013-03-11 07:15 PM
Re: ODBC check using Kix
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Here is the other method, it creates a registry value when it is logged, so that it only logs if the value doesnt exist.
$odbcName = "tess_live_readonly"
$logfile = "C:\ODBC_LOG.txt"
If ReadValue("HKCU\Software\ODBC\ODBC.INI\" + $odbcName,"Logged")<>1
If KeyExist("HKCU\Software\ODBC\ODBC.INI\" + $odbcName) OR KeyExist("HKLM\Software\ODBC\ODBC.INI\" + $odbcName)
$nul = RedirectOutput($logfile)
@Date+" - "+@Time+" - "+$odbcname+" Found on "+@WkSta+" under user "+@UserID ?
$nul = RedirectOutput("")
$nul = WriteValue("HKCU\Software\ODBC\ODBC.INI\" + $odbcName,"Logged",1,"REG_SZ")
Endif
Endif
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 565 anonymous users online.
|
|
|