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

Examples from Users

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

Logging an Automated Install

Keywords: 	  LAFFDB logging an automated install

This is an example of logging an automated install. We use this as a template script, just plugging in our code where needed. This is a working, stand-alone example.

Comment from the developers: Thanks, that's nice looking code. Note that we *might* be canging a bit of how LAFFDB works, so when the next version comes out check the release notes carefully and test before using.


;==========================================================================
; Title:   Logging Database Template
; Date:    03/15/2002
; Author:  Bradley Buskey
; Version: 1.00
; Updated: 03/18/2002
; Purpose: Used to create "live logs" by using a database extender.
; Returns: DATE,TIME,WKID,USERID,OS
; Creates: Success Log - database.txt
;==========================================================================

;==========================================================================
; Declare any needed variables.
;==========================================================================
:Setup
        Section = "Setup"
        IntControl(73,1,0,0,0)
        AddExtender("laffd34i.dll")
        dbFile  = "database.txt"
        LogDate = ""
        LogTime = ""
        WID     = ""
        UID     = ""
        OS      = ""
        FileAttrSet(dbFile,"rsh")
        Goto DoDate
;==========================================================================

;==========================================================================
; This sets up and formats the date and time
;==========================================================================
:DoDate
        Section = "DoDate"
        TheDate = TimeYmdHms()                                                  ; Get the Date (YY:mm:dd:HH:mm:ss)
        DAT1 = ItemExtract(1,TheDate,":")                       ; Year
        DAT2 = ItemExtract(2,TheDate,":")                       ; Month
        DAT3 = ItemExtract(3,TheDate,":")                       ; Day
        DAT4 = ItemExtract(4,TheDate,":")                       ; Hours (24)
        DAT5 = ItemExtract(5,TheDate,":")                       ; Minutes
        DAT6 = ItemExtract(6,TheDate,":")                       ; Seconds
        LogDate = StrCat(DAT2,"/",DAT3,"/",DAT1)        ; Format the date (mm/dd/YY)
        LogTime = StrCat(DAT4,":",DAT5,":",DAT6)        ; Format the time (HH:mm:ss)
        Goto GetWinVer
;==========================================================================

;==========================================================================
; This is where the Windows version and sends the processing to the correct
; function.
;==========================================================================
:GetWinVer
        Section = "GetWinVer"
        MINORVER = Winversion(0)
        MAJORVER = WinVersion(1)
        BUILDVER = WinVersion(2)
        CSDVER =   WinVersion(3)
        PLATFORM = WinVersion(4)
        If majorver == 4 && minorver == 0 && PLATFORM == 5 Then goto Win95
        If majorver == 4 && minorver == 10 && PLATFORM== 5 Then goto Win98
        If majorver == 4 && minorver == 0 && PLATFORM == 4 Then goto WINNT
        If majorver == 5 && minorver == 0 && PLATFORM == 4 Then goto WIN2K
        If majorver == 5 && minorver == 1 && PLATFORM == 4 Then goto WINXP
;==========================================================================

;==========================================================================
; This does anything related to Windows XP
;==========================================================================
:WINXP
        Section = "WinXP"
        OS = "Windows XP"
        Goto DoNTInfo
;==========================================================================

;==========================================================================
; This does anything related to Windows 2K
;==========================================================================
:WIN2K
        Section = "Win2k"
        OS = "Windows 2K"
        Goto DoNTInfo
;==========================================================================

;==========================================================================
; This does anything related to Windows NT
;==========================================================================
:WINNT
        Section = "WinNT"
        OS = "Windows NT"
        Goto DoNTInfo
;==========================================================================

;==========================================================================
; This does anything related to Windows 98
;==========================================================================
:Win98
        Section = "Win98"
        OS = "Windows 98"
        Goto DoWin9xInfo
;==========================================================================

;==========================================================================
; This does anything related to Windows 95
;==========================================================================
:Win95
        Section = "Win95"
        OS = "Windows 95"
        Goto DoWin9xInfo
;==========================================================================

;==========================================================================
; This gathers the information for Windows NT, 2000 and XP
;==========================================================================
:DoNTInfo
        Section = "DoNTInfo"
        WID = Environment ("ComputerName")
        UID = environment("username")
        Goto UpdateDB
;==========================================================================

;==========================================================================
; This gathers the information for Windows 95 and 98
;==========================================================================
:DoWin9xInfo
        Section = "DoWin9xInfo"
        WID = RegQueryValue(@REGMACHINE,"System\CurrentControlSet\control\ComputerName\ComputerName[ComputerName]")
        UID = RegQueryValue(@REGMACHINE,"Network\logon[Username]")
        Goto UpdateDB
;==========================================================================

;==========================================================================
; Does all the database functions including creating if needed, adding the
; column headers, searching for existing wkid, updating existing data and
; adding new data.  Uncomment the dbDebug line when debugging script.
;==========================================================================
:UpdateDB
        Section = "UpdateDB"
        bCreateOK = 0
        Model = 2
        NumCols = -1
        Format = 0
        Delimiter = ","
        OptionString = ""
        dbHandle = dbOpen(dbFile,bCreateOK,Model,NumCols,Format,Delimiter,OptionString)
        If dbHandle == @LAFFDBERROR Then Goto DBERRORHANDLER
        RecordNum = -1
        Flags = 1|4

;<------ Change the Column to match the column name in the database file.  ------>
;<------ Change the FindValue to be the variable or text you want to find. ------>
        Column = "WKID"
        FindValue = "%WID%"
;<------ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ------>

        MatchCase = 0
        ret = dbFindRecord(dbHandle,RecordNum,Flags,Column,FindValue,MatchCase)
        If ret == @LAFFDBERROR Then Goto DBERRORHANDLER
        If ret == -1
                Flags = 4|8
        Else
                RecordNum = ret
                Flags = 1|8
        EndIf
        ColumnList = ""
        Count = dbGetColumnCount(dbHandle)
        For Column = 1 to Count
                ColumnNames = dbGetColumnName(dbHandle,Column)
                ColumnList = StrCat(ColumnList,@TAB,ColumnNames)
        Next
        ColumnList = StrTrim(ColumnList)

;<------ Change this line to match the database headers.  It needs to be 1 to 1 for columns. ------>
        Values = StrCat(LogDate,",",LogTime,",",WID,",",UID,",",OS)  
;<------ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ------>

        For x = 1 to Count
                var = ItemExtract(x,ColumnList,@TAB)
                ret = dbBindCol(dbHandle,x,var)
                If ret == @LAFFDBERROR Then Goto DBERRORHANDLER
                %var% = ItemExtract(x,Values,",")
        Next
        ret = dbSetEntireRecord(dbHandle,RecordNum,Flags)
        If ret == @LAFFDBERROR Then Goto DBERRORHANDLER
        dbSave(dbHandle,"","")
        dbDebug(dbHandle)
        dbClose(dbHandle)
        Exit
;==========================================================================

;==========================================================================
; Error Handler for the database function.  Uncomment the Message line when
; debugging the script.
;==========================================================================
:DBERRORHANDLER
        Section = "DBERRORHANDLER"
        errMessage = dbGetLastError()
        Message("Database Error",errMessage)
        Exit
;==========================================================================

;==========================================================================
; Error Handler for the program.   Used in debugging and to keep errors 
; from user's sight.  Uncomment the dbDebug line when debugging the script.
;==========================================================================
:WBERRORHANDLER
        ErrMes1 = LastError()
        ErrMes2 = wberrorhandlerline
        ErrMes3 = wberrorhandleroffset
        ErrMes4 = IntControl(34,ErrMes1,0,0,0)
        Message("Script Error",StrCat("Error #: ",ErrMes1,@CRLF,"Section: ",Section,@CRLF,"Error Line: ",ErrMes2,@CRLF,"Error Offset: ",ErrMes3,@CRLF,"Error Message: ",ErrMes4))
        Exit
;==========================================================================



Article ID:   W15058
File Created: 2002:09:05:13:49:22
Last Updated: 2002:09:05:13:49:22