Posted: Wed Oct 09, 2002 10:16 pm
Restored from previous forum. Originally posted by Berikco.
Hi,
Here example for reading the event logs.
Will not work in 3.30, Structure TIME_ZONE_INFORMATION is faulty
and no date() functions.
Some messages must be formated using information in the registry
and a resource from the app that generated the event.
This part is not included, looks dificult
Regards,
Berikco
http://www.benny.zeb.be
Hi,
Here example for reading the event logs.
Will not work in 3.30, Structure TIME_ZONE_INFORMATION is faulty
and no date() functions.
Some messages must be formated using information in the registry
and a resource from the app that generated the event.
This part is not included, looks dificult

Code: Select all
#EVNT_SYSTEM = "System"
#EVNT_APP = "Application"
#EVNT_SECURITY = "Security"
#EVENTLOG_SEQUENTIAL_READ = $1
#EVENTLOG_SEEK_READ = $2
#EVENTLOG_FORWARDS_READ = $4
#EVENTLOG_BACKWARDS_READ = $8
Global timezone.TIME_ZONE_INFORMATION
Global UTCtime.SYSTEMTIME
Global localtime.SYSTEMTIME
GetTimeZoneInformation_(@timezone)
Procedure ReadEvents(ServerName,EventType$)
rBuff.EVENTLOGRECORD
StrucLen = SizeOf(EVENTLOGRECORD)
*eBuff=AllocateMemory(1, 16384, 0)
EvtReadFlags = #EVENTLOG_SEQUENTIAL_READ | #EVENTLOG_FORWARDS_READ
EventLogHwd = OpenEventLog_(Servername, EventType$)
If EventLogHwd = 0
ProcedureReturn 0
EndIf
EvtRecNo=0
ret = GetNumberOfEventLogRecords_(EventLogHwd, @EvtRecNo)
If ret = 0
ProcedureReturn 0
EndIf
rBytesRead=0
rBytesNeeded=0
While rBuff\RecordNumber EvtRecNo
ret = ReadEventLog_(EventLogHwd, EvtReadFlags, rBuff\RecordNumber, *eBuff, 16384, @rBytesRead, @rBytesNeeded)
If ret = 0
ProcedureReturn 0
EndIf
eBytePointer = 0
While eBytePointer 0
c$=""
l=0
For r = 1 To rBuff\NumStrings
datum = rBuff\TimeGenerated
UTCtime\wDay = Day(datum)
UTCtime\wMonth = Month(datum)
UTCtime\wYear = Year(datum)
UTCtime\wHour = Hour(datum)
UTCtime\wMinute = Minute(datum)
UTCtime\wSecond = Second(datum)
SystemTimeToTzSpecificLocalTime_(timezone, UTCtime, localtime)
datum = Date(localtime\wYear, localtime\wMonth, localtime\wDay, localtime\wHour, localtime\wMinute, localtime\wSecond)
c$= PeekS(*eBuff + eBytePointer+l + rBuff\StringOffset)
WriteStringN(FormatDate("%YYYY/%mm/%dd %hh:%ii:%ss ", datum)+B$+" "+a$+" "+c$)
l+Len(c$)+1
Next r
EndIf
;EndIf
eBytePointer + EvtRecLen
Wend
Wend
CloseEventLog_(EventLogHwd)
ProcedureReturn 1
EndProcedure
If CreateFile(1,"Eventlog.txt")
ReadEvents(0,#EVNT_APP)
CloseFile(1)
EndIf
End
Berikco
http://www.benny.zeb.be