I'm currently trying to make a program for optimizing people's computers and I'm having a hard time trying to figure out how to read the events from the Windows Event Viewer. Does anyone have any ideas? Thanks
Printable View
I'm currently trying to make a program for optimizing people's computers and I'm having a hard time trying to figure out how to read the events from the Windows Event Viewer. Does anyone have any ideas? Thanks
You can read events via WMI. For example (from msdn.com)
VB Code:
' List Events From a Specific Event Log ' Windows Server 2003 : Yes ' Windows XP : Yes ' Windows 2000 : Yes ' Windows NT 4.0 : Yes ' Windows 98 : No strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * from Win32_NTLogEvent Where Logfile = 'Application'") For Each objEvent in colLoggedEvents Wscript.Echo "Category: " & objEvent.Category Wscript.Echo "Computer Name: " & objEvent.ComputerName Wscript.Echo "Event Code: " & objEvent.EventCode Wscript.Echo "Message: " & objEvent.Message Wscript.Echo "Record Number: " & objEvent.RecordNumber Wscript.Echo "Source Name: " & objEvent.SourceName Wscript.Echo "Time Written: " & objEvent.TimeWritten Wscript.Echo "Event Type: " & objEvent.Type Wscript.Echo "User: " & objEvent.User Next