Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - WMI Programming with Visual Basic.NET: Tra...
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 
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? 
VISUAL BASIC.NET

WMI Programming with Visual Basic.NET: Trapping System Events
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2005-07-25

    Table of Contents:
  • WMI Programming with Visual Basic.NET: Trapping System Events
  • Creating a simple application
  • What is “WqlEventQuery”?
  • Watching the event

  • 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


    WMI Programming with Visual Basic.NET: Trapping System Events - What is “WqlEventQuery”?


    (Page 3 of 4 )

    Let me explain the above program line by line. Consider the first statement:

    DimqueryAsNewWqlEventQuery( _

                     "__InstanceModificationEvent", _

                    NewTimeSpan(0, 0, 1), _

                     "TargetInstance isa ""Win32_Service""")

    We see from the above statement that we are about to work with a new class “WqlEventQuery” in “System.Management” namespace. This is the class specially used to work with event based queries in WMI.

    The “__InstanceModificationEvent” is a special WMI system class used to report an instance of a modification event, which is a type of intrinsic event generated when an instance changes (gets modified) in the namespace. Any event, treated as modification to a state of the event, will be immediately notified to this class.  We also have similar event classes like “__InstanceCreationEvent” and “__InstanceDeletionEvent”.  But all these get inherited from “__InstanceOperationEvent” class.  And even “__InstanceOperationEvent”  gets inherited from “__Event”.  You can get an entire hierarchy of these classes from WMI SDK documentation.

    The value of an instance of “TimeSpan” class represents a period of time. This interval is the maximum amount of time that can pass before notification of an event must be delivered. That means something like “send notification of the creation (or modification) of Win32_Service instances, with a ‘specified timespan’ of polling interval”. “TimeSpan(0,0,1)” specifies a time interval of zero hours, zero minutes and one second. So, it polls every second.

    “__InstanceModificationEvent” may be reporting several types of instances and not only “Win32_Service” based events. So, we need to filter the events to only the ones we want (in this case, the events of type “Win32_Service”).  Any instance of “__InstanceModificationEvent” has a property named “TargetInstance”. This property is the instance used to fire the event. In this case we are checking whether it is an instance of “Win32_Service” event being fired or not.  If you carefully observe, there exists a keyword, “isa” keyword, which is defined as an operator in WQL. It is generally used to compare directly with the instances (rather than to the property values).

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


     

    VISUAL BASIC.NET ARTICLES

    - 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...
    - Creating and Drawing a Game Map in VB.NET (F...
    - 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 ...





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