Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Managing `EventLog` using Visual Basic.NET...
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? 
VISUAL BASIC.NET

Managing `EventLog` using Visual Basic.NET and VBScript
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2006-01-18

    Table of Contents:
  • Managing `EventLog` using Visual Basic.NET and VBScript
  • How to list all “Blue Screen” events (or STOP errors) using Visual Basic.NET
  • How to clear “EventLog” dynamically using Visual Basic.NET
  • How to copy “EventLog” information into a text file using Visual Basic.NET

  • 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


    Managing `EventLog` using Visual Basic.NET and VBScript - How to clear “EventLog” dynamically using Visual Basic.NET


    (Page 3 of 4 )

    We have already seen how to take a backup of “EventLog” in the previous section.  Now let us look into “clearing an EventLog”.  Since we are doing manipulation instead of retrieving information, this section does not need any wrapper to work with.

    Let us proceed with the Visual Basic.NET version first:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
    As System.EventArgs) Handles Button2.Click
     
            Try
     
                Dim classInstance As New ManagementObject( _
                    "root\CIMV2",
    "Win32_NTEventlogFile.Name='C:\WINDOWS\system32
    \config\AppEvent.Evt'", Nothing)
     
                Dim inParams As ManagementBaseObject = _
                    classInstance.GetMethodParameters
    ("ClearEventlog")
     
                Dim outParams As ManagementBaseObject = _
                    classInstance.InvokeMethod("ClearEventlog",
    inParams, Nothing)
                MessageBox.Show("Return Value " & outParams
    ("ReturnValue"))
     
            Catch err As ManagementException
     
                MessageBox.Show("An error occurred while trying to
    execute the WMI method: " & err.Message)
            End Try
        End Sub

    “inParams” (which is of type System.Managment.ManagmentBaseObject) is mainly used to pass parameters (input parameters) to the “ClearEventLog” method (WMI method) dynamically.  Similarly, “outParams” generally contains the result of method execution. 

    Again, here is the VBScript version, which would be very similar to the Visual Basic.NET version:

     strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer &
    "\root\CIMV2")
    Set objShare = objWMIService.Get
    ("Win32_NTEventlogFile.Name='C:\WINDOWS\system32
    \config\AppEvent.Evt'")
    Set objInParam = objShare.Methods_("ClearEventlog"). _
        inParameters.SpawnInstance_()
    Set objOutParams = objWMIService.ExecMethod
    ("Win32_NTEventlogFile.Name='C:\WINDOWS\system32
    \config\AppEvent.Evt'", "ClearEventlog", objInParam)
    Wscript.echo "ReturnValue: " & objOutParams.ReturnValue

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello, Now you can manage event log dynamically. Just read and enjoy. You can...
       · i am not getting it, how to generate the log. i can only see the datagrid. can u plz...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT