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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    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

    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway