Windows Scripting
  Home arrow Windows Scripting arrow More Event Scripting with WMI
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? 
WINDOWS SCRIPTING

More Event Scripting with WMI
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-05-15

    Table of Contents:
  • More Event Scripting with WMI
  • Using __InstanceModificationEvent
  • Parsing WMI’s results
  • Using __InstanceOperationEvent

  • 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


    More Event Scripting with WMI


    (Page 1 of 4 )

    In the first article of this series we saw how WMI can be used to build an event driven script. In this segment we will be learning what other events WMI makes available to us. Let’s get started.

    Before we begin, let’s take another look at the code from the last article.  We’ll be using that as the base for all of the samples in this one.

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" & strComputer _

       & "rootcimv2")

     

    Set colEvents = objWMIService.ExecNotificationQuery _

       ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _

          & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _

          & "TargetInstance.GroupComponent= " _

          & "'Win32_Directory.Name=""c:\test""'")

     

    Do While True

       Set objEvent = colEvents.NextEvent()

       WScript.Echo "File Deleted:", _

           objEvent.TargetInstance.PartComponent

    Loop

    As we’ve learned, this code watches the C:test folder for file deletions.  We connect to the WMI service, issue an event based query, and then process the results in an endless Do…Loop.

    The important things to note here are the use of the __InstanceCreationEvent event and the use of the NextEvent function to move through returned events.

    We’re going to be using this same construct with our next event.  We’ll simply plug in a new event and the code will function in an identical fashion.

    We know how to watch for creations.  We also know how to watch for deletions.  The third event type we’ll be looking at will watch for modifications.  Again, our examples will be watching for files, but this could easily be altered to watch for changed registry keys or any other scriptable object.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · Learn what other events are made available by WMI.
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





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