I never had any luck with the WMI event query since it tends to do an endless loop during the query. I had to resort to the Microsoft DUMPEL.EXE utility from the link at
I have following code that I wrote for my event log query. It always works for me.
===================================================
Option Explicit
Dim strComputer, strLogFile, strDay, arrEvtData, objItem
strComputer = "MySERVER"
strLogFile = "Application"
strDay = 1
arrEvtData = getEventLogInfo(strComputer, strLogFile, strDay)
For Each objItem In arrEvtData
Wscript.Echo objItem
Next
' Function to run dumpel.exe utility to query the event log information.
Private Function getEventLogInfo(strComputer, strLogFile, strDay)
Dim objDicData, objShell, objExecObject, strDataSource, strData, strDate
Dim strTime, strType, strID, strSource, strDesc, dtmDateTime, arrData
Dim strDateSelect
PrintMsg3 "Querying event log information on " & strComputer & ". Please wait. . ."
Set objDicData = CreateObject("Scripting.Dictionary")
Set objShell = Wscript.CreateObject("Wscript.Shell")
Set objExecObject = objShell.Exec _
("%comspec% /c dumpel -s \\" & strComputer & " -l " & strLogFile & _
" " & " -d " & strDay & " -t -format dtITSs")
' Event Type (T): 1 = Error, 2 = Warning, 4 = Information
Do While Not objExecObject.StdOut.AtEndOfStream
strDataSource = objExecObject.StdOut.ReadLine
If strDataSource <> "Dump successfully completed." Then
strData = Split(strDataSource, vbTab)
strDate = strData(0) : strTime = strData(1) : strID = strData(2)
strType = strData(3) : strSource = strData(4) : strDesc = strData(5)
Select Case strType
Case 1
strType = "Error"
Case 2
strType = "Warning"
Case 4
strType = "Information"
End Select
If Len(strDesc) > 0 Then
If objDicData.Count > 75 Then Exit Do ' Limit the event log number to 75.
strDesc = Split(strDesc, ".")(0) & "."
dtmDateTime = strDate & " " & strTime
arrData = strDate & vbTab & strTime & vbTab & strID & vbTab & _
strType & vbTab & strSource & vbTab & Replace(strDesc, Chr(34), "")
' Select only the events from last 24 hours and event type is either error or warning.
strDateSelect = DateDiff("s", dtmDateTime, Now)
'If strDateSelect =< 864000 And strType <> "Information" Then ' 10 days.
'If strDateSelect =< 432000 And strType <> "Information" Then ' 5 days.
If strDateSelect =< 86400 And strType <> "Information" Then ' 1 day.
objDicData.Add objDicData.Count, arrData
End If
End If
End If
Loop
If objDicData.Count > 0 Then
getEventLogInfo = SortEventData(objDicData.Items)
Else
getEventLogInfo = Array("")
End If
' Clean up variables.
Set objDicData = Nothing: Set objShell = Nothing: Set objExecObject = Nothing
End Function
' Function to sort the event log data.
Function SortEventData(arrData)
Dim dicDataList, DataList, objItem, strData, strDateTime, strDate
Dim strID, strType, strSource, strDesc
Set dicDataList = CreateObject("Scripting.Dictionary")
Set DataList = CreateObject("ADODB.Recordset")
DataList.Fields.Append "strEventDate", 7 ' adVarDate
DataList.Fields.Append "strEventID", 200, 255 ' adVarChar
DataList.Fields.Append "strEventType", 200, 255 ' adVarChar
DataList.Fields.Append "strEventSrc", 200, 255 ' adVarChar
DataList.Fields.Append "strEventDesc", 200, 255 ' adVarChar
DataList.Open
For Each objItem In arrData
strData = Split(objItem, vbTab)
strDateTime = strData(0) & " " & strData(1)
DataList.AddNew
DataList("strEventDate") = strDateTime
DataList("strEventID") = strData(2)
DataList("strEventType") = strData(3)
DataList("strEventSrc") = strData(4)
DataList("strEventDesc") = strData(5)
DataList.Update
Next
If DataList.RecordCount > 0 Then 'Used for trapping null record.
DataList.Sort = "strEventDate DESC" ' Sort date and time by descending order.
DataList.MoveFirst
Do Until DataList.EOF
strDate = getDateTime(DataList.Fields.Item("strEventDate"))
strID = DataList.Fields.Item("strEventID")
strType = DataList.Fields.Item("strEventType")
strSource = DataList.Fields.Item("strEventSrc")
strDesc = DataList.Fields.Item("strEventDesc")
strData = strDate & vbTab & strID & vbTab & strType & vbTab & strSource & vbTab & strDesc
dicDataList.Add dicDataList.Count, strData
DataList.MoveNext
Loop
End If
SortEventData = dicDataList.Items
' Clean up variables.
Set dicDataList = Nothing: Set DataList = Nothing
End Function
' Function to split event date and time after sorting.
Private Function getDateTime(strDateTime)
Dim strDate, strTime
strDate = Split(strDateTime)(0)
strTime = Split(strDateTime)(1) & " " & Split(strDateTime)(2)
getDateTime = strDate & vbTab & strTime
End Function
' Sub routin to print message.
Private Sub PrintMsg (ByVal strMessage)
Wscript.StdOut.WriteBlankLines(1)
Wscript.StdOut.WriteLine Space(3)& strMessage
End Sub
================================================
CluM09