Solved

Query archived Windows Event Logs with WMI

Posted on 2003-11-01
7
490 Views
Last Modified: 2010-04-13
Using WMI, how can I harvest events in a backed up event log file? I know how to read the current event log, but don't know how to query one that has been backed up and cleared.

Thanks.
0
Comment
Question by:gwiensx
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:Bigjohn-s
ID: 9664860
0
 

Author Comment

by:gwiensx
ID: 9664963
Well, I guess I wasn't clear about how I wanted to access the archived log. I know I can view the archived events with the event viewer, but I need to do it using a WMI script.
0
 
LVL 2

Expert Comment

by:Bigjohn-s
ID: 9666046
Then you need to archive the events as comma delimited values (CSV).  You can then use any application to access those events - it's just a text file.

John
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:gwiensx
ID: 9666785
Here is the code I use to clear the current Application event log, saving these events to an event file.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup)}!\\" & _
strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='Application'")
For Each objLogfile in colLogFiles
errBackupLog = objLogFile.BackupEventLog("c:\scripts\application.evt")
If errBackupLog <> 0 Then
Wscript.Echo "The Application event log could not be backed up."
Else
objLogFile.ClearEventLog()
End If
Next


What I am looking for is WMI code which would then let me read from this file -- code similar to the code that follows, but point it to the file I created above:

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

I have tried modifying the "select" statement above as follows, but his does not work:

("Select * from Win32_NTLogEvent Where Logfile = 'Application' and NTEventlogFile = 'C:\GWiens\Code\WinScripts\EventLog\application.evt'")

0
 
LVL 2

Accepted Solution

by:
Bigjohn-s earned 500 total points
ID: 9667025
I'm not a WMI scripter.  But I think if you were saving / exporting the data as CSV, you could then use your script to access it.
0
 

Author Comment

by:gwiensx
ID: 9679939
My research shows that apparently there is not currently a way to read archived binary event files without additional enhancements such as proprietary extensions, etc.
0
 
LVL 2

Expert Comment

by:Bigjohn-s
ID: 9680206
Thanks for the points.  Sorry the answer was not what you expected.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now