Windows Scripting
  Home arrow Windows Scripting arrow Advanced Event Log Parsing in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Advanced Event Log Parsing in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-05-22

    Table of Contents:
  • Advanced Event Log Parsing in WSH
  • Filtering results
  • More filtering examples
  • Making the code reusable

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Advanced Event Log Parsing in WSH


    (Page 1 of 4 )

    In the first part of this series, we took a look at how to parse event logs and write that information to a database. We’re going to build on that script today and show you some more advanced techniques as well as some specific applications for this type of script.

    Before we get too involved, let’s revisit the script from the last article:

    strComputer = "."

    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " _

       & "Data Source=C:events.mdb"

     

    Set objWMIService = GetObject("winmgmts: " _

       "{impersonationLevel=impersonate}!" & strComputer _

       & "rootcimv2")

    Set colEvents = objWMIService.ExecQuery( _

       "SELECT * FROM Win32_NTLogEvent")

    In the first section, we set some variables we’ll need later and query the WMI service for all of the events in the events logs.

    Set objCatalog = CreateObject("ADOX.Catalog")

    objCatalog.Create strConnection

    Set objCatalog = Nothing

    Set oConn = CreateObject("ADODB.Connection")

    oConn.Open strConnection

    oConn.Execute "CREATE TABLE EventTable(" _

       & "Category INT, " _

       & "ComputerName VARCHAR(50), " _

       & "EventCode INT, " _

       & "Message VARCHAR(100), " _

       & "EventType VARCHAR(50), " _

       & "RecordNumber INT, " _

       & "SourceName VARCHAR(50), " _

       & "TypeDesc VARCHAR(15), " _

       & "UserName VARCHAR(50), " _

       & "TimeGenerated VARCHAR(19), " _

       & "TimeWritten VARCHAR(19)" _

       & ")", , 129

    Next, we create a database and add a table to store our data.  Once we’ve added some fields we’re ready to go.

    Set objRs = CreateObject("ADODB.Recordset")

    objRs.Open "SELECT * FROM EventTable;", oConn, 0, 3

    We now create a record set for our database table.

    For Each objEvent In colEvents

       Set objEvent = colEvents.NextEvent()

       objRs.AddNew

       objRs("Category") = objEvent.Category

       objRs("ComputerName") = objEvent.ComputerName

       objRs("EventCode") = objEvent.EventCode

       strMessage = objEvent.Message

       If Len(strMessage) > 100 Then strMessage = Left(strMessage, 100)

       objRs("Message") = strMessage

       objRs("EventType") = objEvent.EventType

       objRs("RecordNumber") = objEvent.RecordNumber

       objRs("SourceName") = objEvent.SourceName

       objRs("TypeDesc") = objEvent.Type

       strUser = objEvent.User

       If IsNull(strUser) Then strUser = "N/A"

       objRs("UserName") = strUser

       objRs("TimeGenerated") = Date2String(objEvent.TimeGenerated)

       objRs("TimeWritten") = Date2String(objEvent.TimeWritten)

       objRs.Update

    Next

    A For Each…Next loop moves through each of the events in the collection returned by our WMI query and adds them to our record set.

    objRs.Close

    oConn.Close

    Finally, both the record set and ADODB connection are closed.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · In this article, you'll learn specific ways to customize your event log script for...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek