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  
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 
IBM developerWorks
 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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

    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory




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