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

WMI Programming with Visual Basic.NET: More About Trapping System Events
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2005-08-01

    Table of Contents:
  • WMI Programming with Visual Basic.NET: More About Trapping System Events
  • Creating a better application
  • Is there any other good example to work with?
  • What about __InstanceDeletionEvent?

  • 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

    Ajax Application Generator Generate database 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!

    WMI Programming with Visual Basic.NET: More About Trapping System Events - Is there any other good example to work with?


    (Page 3 of 4 )

    Why not? We can develop several other examples with the same concept. Until now, I have always been working with the “Win32_Service” class only. Not let us start with another class, “Win32_Process”.  Part three and part five of this series have already discussed this class (but not to the events level).  Now, I would like to modify the above created application, so that it subscribes to the class “Win32_Process”.

    You need to modify the WQL query as follows:

    Dim query As WqlEventQuery = New WqlEventQuery( _
      "__InstanceCreationEvent", _
      New TimeSpan(0, 0, 1), "TargetInstance isa ""Win32_Process""")

    And the event handler as following:

    Public Sub HandleEvent(ByVal sender As Object, ByVal _
    e As EventArrivedEventArgs)
     
    Dim ev AsManagementBaseObject = e.NewEvent
     
    TextBox1.Text &= ControlChars.NewLine & _
       
    "Process '" &CType(ev("TargetInstance"), ManagementBaseObject)("Name") & "' started"

            TextBox1.Refresh()

    EndSub

    That’s it. We are finished. Try executing it. Press the start button after you execute your application. It starts listening to events. To notify the listener, open any application such as “notepad”, “calculator”, “PaintBrush” etc. When you open any application, the WMI treats it as a new process and notifies our application of the event. You should be able to observe that the textbox gets updated accordingly (with “process started” messages).  Finally stop the subscription of events by clicking on button “stop”. Is it not interesting?

    Did you observe the above code carefully?  I replaced “__InstanceModificationEvent” with “__InstanceCreationEvent”. This is very important as we are “creating” (opening) a new process, but not modifying an existing process.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


     

    VISUAL BASIC.NET ARTICLES

    - 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
    - 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...





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