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

Event Logs

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

Read Event Log via WMI

 Keywords:  Event log eventlog 

This is a starter string that allows reading of the system event log via WMI.


;This code reads the event log
;Lots can be added, like filtering on time or record number

Locator = ObjectOpen("WbemScripting.SWbemLocator")
Service = Locator.ConnectServer()
Security = Service.Security_
Security.ImpersonationLevel = 3

LogSet = Service.InstancesOf("Win32_NTLogEvent")

hEnum = ObjectCollectionOpen(LogSet)

While 1
  objEvent = ObjectCollectionNext(hEnum)
  If objEvent == 0 Then Break
  line=objEvent.Category
  line=StrCat(line,@TAB,objEvent.ComputerName)
  line=StrCat(line,@TAB,objEvent.EventCode)
  line=StrCat(line,@TAB,objEvent.Message)
  line=StrCat(line,@TAB,objEvent.RecordNumber)
  line=StrCat(line,@TAB,objEvent.SourceName)
  line=StrCat(line,@TAB,objEvent.TimeWritten)
  line=StrCat(line,@TAB,objEvent.Type)
  line=StrCat(line,@TAB,objEvent.User)



  x=AskYesNo("Category",StrReplace(line,@TAB,@CRLF))
  If x==@NO Then Break
  ObjectClose(objEvent)
EndWhile

ObjectCollectionClose(hEnum)

ObjectClose(LogSet)

ObjectClose(Security)
ObjectClose(Service)
ObjectClose(Locator)


Exit

Article ID:   W15696
File Created: 2003:05:28:10:22:58
Last Updated: 2003:05:28:10:22:58