WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

SQLite

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Multi Browser History Report

 Keywords: Browser History SQLite SQLite3 ODBC Driver Chrome FireFox Internet Explorer 

;Winbatch 2010C - multiple browser history
;
;Script sets up an INI file to determine if Firefox or Chrome
;browser histories are present and installs SQLite ODBC driver
;to access their content [must be present].
;
;Script then sends information to a designated email address.
;Therefore, review the script and make necessary changes before
;testing in your environment.
;
;Script should be compiled to run hidden. I have it set up on
;user PC's as a scheduled task.
;
;
;NOTE: the script installs the SQLite ODBC Driver in the dir where
;      the script is run. You can modify to move driver to the
;      System32 folder and install from there.
;      There is a lot of room to improve this script, it does what
;      it needs to do in simplest terms. Posted improvements are welcome.
;
;Stan Litlefield, May 5, 2011
;///////////////////////////////////////////////////////////////////////////////////////////////////

;!!!!!!!!!MODIFY TO FIT YOUR NEEDS !!!!!!!!!!
; set up your own email
host="mail.myemailserver.com"
fromaddr="soandso@hereorthere.com"
userid="soandso"
password="N0neOfYourBeesWax"
port=""
sendto="soandso@hereorthere.com"


GoSub udfs
IntControl(73,1,0,0,0)
IntControl(65, 10000, 0, 0, 0)
IntControl(1007,2,0,0,0)
;load necessary extenders
AddExtender("WWPST44I.DLL")
AddExtender("wsrch34i.dll")
AddExtender("wwipg34i.dll")
cINI=""
cUser = Environment("USERNAME")

chkconfig() ;hopefully only has to be run once
            ;but if user adds FF or Chrome, just delete the ini
            ;and the script will re-build it

fh=""
cIP=""
cIP=ipa()   ;want to associate by the IP address

fh="INTERNET EXPLORER":@CRLF
fh=fh:"User":@TAB:"Date":@TAB:"Title":@TAB:"URL":@CRLF

;if you merely want to export data to a text file
;cOut=dirscript():"places.txt"
;If FileExist(cOut) Then FileDelete(cOut)


sh = CreateObject("Shell.Application")
ssfHISTORY = 34
history = sh.NameSpace(ssfHISTORY)

ForEach item In history.items
  If item.isFolder
    itFol = item.GetFolder
    ForEach item2 In itFol.items
      If item2.isFolder
        itFol2 = item2.GetFolder
        ForEach item3 In itFol2.items
           fh=fh:cUser:@TAB:itFol2.GetDetailsOf(item3,2):@TAB:itFol2.GetDetailsOf(item3,1):@TAB
           fh=fh:itFol2.GetDetailsOf(item3,0):@CRLF
        Next
      EndIf
    Next
  EndIf
Next

sh=0
tries=0

:sqlite
If isSQLite

   fh=fh:@CRLF:"FIREFOX":@CRLF

   If isFF
      ;create an ADO connection and query for sites browsed
      cConn= "DRIVER=SQLite3 ODBC Driver;Database=":FFPath:";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;"
      oConn=CreateObject("ADODB.Connection")
      oConn.Open(cConn)
      oRS=CreateObject("ADODB.Recordset")

      cSQL="SELECT datetime(moz_historyvisits.visit_date/1000000,'unixepoch','localtime'), moz_places.url  "
      cSQL=cSQL:"FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id;"

      oRS.Open(cSQL,oConn,1,3,1)
      If ! oRS.eof Then fh=fh:oRS.GetString(2,,,@CRLF,):@CRLF
      oRS.Close()
      oRS=0
      oConn.Close()
      oConn=0
   Else
      fh=fh:"Cannot Find Firefox Browser History":@CRLF
   EndIf

   fh=fh:@CRLF:"CHROME":@CRLF



   If isChrome
      ;create an ADO connection and query for sites browsed
      cConn= "DRIVER=SQLite3 ODBC Driver;Database=":ChromePath:";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;"
      oConn=CreateObject("ADODB.Connection")
      oConn.Open(cConn)
      oRS=CreateObject("ADODB.Recordset")

      ;time stamp is microseconds since January, 1601
      cSQL="SELECT url,datetime(last_visit_time/1000000-11644473600,'unixepoch','localtime') FROM urls;"

      oRS.Open(cSQL,oConn,1,3,1)
      If ! oRS.eof Then fh=fh:oRS.GetString(2,,,@CRLF,):@CRLF
      oRS.Close()
      oRS=0
      oConn.Close()
      oConn=0

   Else
      fh=fh:"Cannot Find Chrome Browser History":@CRLF
   EndIf

Else
   If tries>2
      If ! instsqlite()
         fh=fh:"SQLITE ODBC Driver Missing":@CRLF
      Else
         Goto sqlite
      EndIf
   EndIf
EndIf


:End
;if you merely want to export data to a text file
;FilePut(cOut,fh)

SendEmail(host,fromaddr,userid,password,port,sendto)
Exit

:WBERRORHANDLER
ErrorProcessing(1,1,0,0)
SendEmail(host,fromaddr,userid,password,port,sendto)
Exit

;///////////////////////////////////////////////////////////////////////////////////////////////////
:udfs
#DefineSubRoutine ErrorProcessing(deleteIni,showerr,logfile,Err_Array)
If VarType(Err_Array) ==256
   WbError = Err_Array[0]
   wberrorhandlerline = Err_Array[1]
   wberrorhandleroffset = Err_Array[2]
   wberrorhandlerassignment = Err_Array[3]
   wberrorhandlerfile = Err_Array[4]
   wberrortextstring = Err_Array[5]
   wberroradditionalinfo = Err_Array[6]
   wberrorinsegment = Err_Array[7]
Else
   WbError = LastError()
EndIf
WbTextcode = WbError
If WbError==1668||WbError==2669||WbError==3670
   ; 1668 ; "Minor user-defined error"
   ; 2669 ; "Moderate user-defined error"
   ; 3670 ; "Severe user-defined error"
   WbError = ItemExtract(1,IntControl(34,-1,0,0,0),":")
   WbTextcode = -1
EndIf
WbErrorString = IntControl(34,WbTextcode,0,0,0)
WbErrorDateTime = TimeYmdHms()
WbErrorFile = StrCat(DirWindows(0),"WWWBATCH.INI")
If deleteIni
   FileDelete(WbErrorFile)
   IniWritePvt(WbErrorDateTime,"CurrentScript",WbErrorHandlerFile      ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ErrorValue"   ,WbError                 ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ErrorString"  ,WbErrorString           ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ScriptLine"   ,WbErrorHandlerLine      ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ScriptOffset" ,WbErrorHandlerOffset    ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"VarAssignment",WbErrorHandlerAssignment,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"VarInSegment" ,WbErrorInSegment,WbErrorFile)
   IniWritePvt("","","",WbErrorFile)
EndIf
WbErrorMsgText = StrCat(WbErrorDateTime,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Current Script: ",WbErrorHandlerFile,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Error# [",WbError,"]",@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Error Text: ",wberrortextstring,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"[Extended Information] ",wberroradditionalinfo,@CRLF,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"On Line:",@CRLF,WbErrorHandlerLine,@CRLF)
;WbErrorMsgText = StrCat(WbErrorMsgText,"Offset: ",WbErrorHandlerOffset,@CRLF)
If (WbErrorHandlerAssignment>"") Then %WbErrorHandlerAssignment% = "UNKNOWN"
WbErrorMsgText = StrCat(WbErrorMsgText,"Assignment/Variable: ",WbErrorHandlerAssignment,@CRLF)
If (WbErrorInSegment>"") Then WbErrorMsgText = StrCat(WbErrorMsgText,"In UDF/UDS: ",WbErrorInSegment,@CRLF)
If logfile
   cSep = StrCat(StrFill("=",50),@CRLF)
   cLogFile = StrCat(DirScript(),"log.err")
   If ! FileExist(cLogFile) Then FilePut(cLogFile,StrCat("Error Log",@CRLF,cSep))
   FilePut(cLogFile,StrCat(FileGet(cLogFile),WbErrorMsgText,cSep))
   Display(2,"An Error Occured",StrCat("written to ",cLogFile))
Else
   If showerr
      WbErrorMsgText = StrCat(WbErrorMsgText,"[THIS ERROR NOT WRITTEN TO LOG FILE]",@CRLF)
      fh=WbErrorMsgText
   EndIf
EndIf
Return(1)
#EndSubRoutine

#DefineSubRoutine SendEmail(host,fromaddr,userid,password,port,sendto)
kInit(host,fromaddr,userid,password,port)
kDest(sendto,"","")
ret = kSendText("IP:":cIP,fh,"","")
If ret == 0
   kInit(host,fromaddr,userid,password,port)
   kDest(sendto,"","")
   ret = kSendText("IP:":cIP,"Error Getting Browser History":@CRLF:kStatusInfo():@CRLF,"","")
EndIf
Return(1)
#EndSubRoutine

#DefineFunction ipa() ;taken straight from WB manual
ips=ipGetAddress()
count=ItemCount(ips,@TAB)
bestaddr=""
bestsubnet=""
For xx=1 To count
   thisipstring=ItemExtract(xx,ips,@TAB)
   ip=ItemExtract(1,thisipstring,"|")
   sub=ItemExtract(2,thisipstring,"|")
   brd=ItemExtract(3,thisipstring,"|")
   flags=ItemExtract(4,thisipstring,"|")
   show=StrCat(ip,@CRLF,sub,@CRLF,brd,@CRLF,StrReplace(flags," ",@CRLF))
   ;fish out a usable IP address
   ;a) no better address already found
   ;b) ip address not 0.0.0.0
   ;c) LOOPBACK bot set
   If bestaddr!="" Then Continue
   If ip=="0.0.0.0" Then Continue
   If ItemExtract(1,flags," ")=="DOWN" Then Continue
   If ItemExtract(4,flags," ")=="LOOPBACK" Then Continue
   If StrIndex(ip,"10.",0,@FWDSCAN)>0 ;indicate a portion of your local IP range
                                      ;to avoid getting an invalid VMWare IP
      bestaddr=ip
      bestsubnet=sub
   EndIf
Next
Return(bestaddr)
#EndFunction

#DefineSubRoutine instsqlite()
cDriver = DirScript():"sqlite3odbc.dll"
If ! FileExist(cDriver) Then Return(0)
RunWait( "rundll32.exe", "%cDriver%,install" )
Return(1)
#EndSubRoutine

#DefineSubRoutine chkconfig()
cINI=DirScript():"config.ini"
If ! FileExist(cINI)
   IniWritePvt("Main", "SQLite", 0, cINI)
   IniWritePvt("Main", "ChromePath", "N/A", cINI)
   IniWritePvt("Main", "FFPath", "N/A", cINI)
   IniWritePvt("Main", "Chrome", 0, cINI)
   IniWritePvt("Main", "FF", 0, cINI)
   If !StrIndex(RegQueryItem(@REGMACHINE, "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"),"SQLite3 ODBC Driver",0,@FWDSCAN)>0
      If instsqlite() Then IniWritePvt("Main", "SQLite", 1, cINI)
   Else
      IniWritePvt("Main", "SQLite", 1, cINI)
   EndIf
   ff()
   chrome()
EndIf

isSQLite= IniReadPvt("Main", "SQLite", 0, cINI)
isFF= IniReadPvt("Main", "FF", 0, cINI)
isChrome= IniReadPvt("Main", "Chrome", 0, cINI)
FFPath= IniReadPvt("Main", "FFPath", "", cINI)
ChromePath= IniReadPvt("Main", "ChromePath", "", cINI)

Return(1)
#EndSubRoutine

#DefineSubRoutine ff()
hand=SrchInit("C:\","places.sqlite","","",16)
c=0
fnd=0
While 1
   cDB=SrchNext(hand)
   If cDB=="" Then Break
   c=c+1
   If StrIndex(cDB,cUser,0,@FWDSCAN)>0 && StrIndex(cDB,"Mozilla",0,@FWDSCAN)>0
      IniWritePvt("Main", "FF", 1, cINI)
      IniWritePvt("Main", "FFPath", cDB, cINI)
      fnd=1
      Break
   EndIf
EndWhile
SrchFree(hand)
Return(fnd)
#EndSubRoutine

#DefineSubRoutine chrome()
hand=SrchInit("C:\","History","","",16)
c=0
fnd=0
While 1
   cDB=SrchNext(hand)
   If cDB=="" Then Break
   c=c+1
   If StrIndex(cDB,cUser,0,@FWDSCAN) && StrIndex(cDB,"Chrome",0,@FWDSCAN)
      IniWritePvt("Main", "Chrome", 1, cINI)
      IniWritePvt("Main", "ChromePath", cDB, cINI)
      fnd=1
      Break
   EndIf
EndWhile
SrchFree(hand)
Return(fnd)
#EndSubRoutine

Return
;///////////////////////////////////////////////////////////////////////////////////////////////////

Article ID:   W18197
Filename:   Multi Browser History Report.txt
File Created: 2011:06:07:13:33:56
Last Updated: 2011:06:07:13:33:56