[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Query archived Windows Event Logs with WMI

Posted on 2003-11-01
7
Medium Priority
?
506 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
 

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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 

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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

829 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