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

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 / 10
    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


    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

    - Clocks and Countdowns
    - 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...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek