Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
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? 
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
     
    Iron Speed
     
    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!

    Managing `EventLog` using Visual Basic.NET and VBScript - How to copy “EventLog” information into a text file using Visual Basic.NET


    (Page 4 of 4 )

    We have already seen how to take a backup of “EventLog” in the previous sections.  Now let us look into “copying an EventLog into a text file.”  Even this section does not need any wrapper, as we are not retrieving any information.

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

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
    As System.EventArgs) Handles Button3.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("Copy")
     
                inParams("FileName") = "c:\sample.txt"
     
                Dim outParams As ManagementBaseObject = _
                    classInstance.InvokeMethod("Copy", inParams,
    Nothing)
     
                Console.WriteLine("Out parameters:")
                Console.WriteLine("ReturnValue: {0}", 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 “Copy” method (WMI method) dynamically.  Now we are trying to pass a file name as part of the input parameter (which is a bit different from previous sections).  The input parameter is assigned as follows:

                inParams("FileName") = "c:\sample.txt"

    Similarly, “outParams” generally contains the result of method execution. 

    Here is the VBScript version, which is 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_("Copy"). _
        inParameters.SpawnInstance_()
    objInParam.Properties_.Item("FileName") =  "c:\sample.txt"
     
    Set objOutParams = objWMIService.ExecMethod
    ("Win32_NTEventlogFile.Name='C:\WINDOWS\system32
    \config\AppEvent.Evt'", "Copy", objInParam)
     
    Wscript.echo "ReturnValue: " & objOutParams.ReturnValue

    How about deleting, compressing, and similar types of operations on “EventLog” using Visual Basic.NET?

    As the coding is quite similar to the above for the features like deleting, compressing, and so on, I just wanted to provide some of the most useful methods available within the “Win32_NTEventLogFile” class.  By using these methods, you can still write your own routines, which could be the extensions of the above routines.

    Following is the list of methods in the class “Win32_NTEventLogFile”, which you might find useful:

    Compress
    CompressEx
    Copy
    CopyEx
    Delete
    DeleteEx
    Rename
    UnCompress
    UnCompressEx

    You need to check through the MSDN library for the parameters of the methods along with descriptions and usage. But the program skeleton to work with the above methods will be very similar to the ones I provided above.

    Currently, I used VB.NET (especially for programmers) and VBScript (for system administrators) to manage the EventLog.  But if you would like to manage EventLog remotely using the web, I suggest you use ASP.NET. The coding will be very similar to that of VB.NET.  But be sure to make some modifications towards ASP.NET security to work with EventLog.  Further, you can extend the same to the PocketPC level, just to manage EventLog, by developing a Smart Device application. 

    Any comments, suggestions, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello, Now you can manage event log dynamically. Just read and enjoy. You can...
     

    VISUAL BASIC.NET ARTICLES

    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...




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