Windows Scripting
  Home arrow Windows Scripting arrow 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

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

    Table of Contents:
  • Event Scripting with WMI
  • Introduction to WMI
  • Using __InstanceCreationEvent
  • Using __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


    Event Scripting with WMI


    (Page 1 of 4 )

    So you’re really starting to figure out this whole scripting thing. That’s great, but now you’re beginning to realize that you want your scripts to work more like full applications, right? Let’s learn a way to bridge the gap between scripting and full-blown application development.

    We all know that you can create a script to perform a given list of procedures.  That’s cool.  We even know that we can schedule or loop them to make them recurring.  That’s nifty too.  But what you really want is to be able to write a script that reacts to something else!

    How about a script that restarts your web server if it crashes?  Or how about a script that maintains an order database every time you receive an email order?  Now those would be useful scripts.

    There’s just one problem.  How can WSH know when those particular things occur?  The answer is simple.  It’s called Event Programming—and lucky for us, both VBScript and WMI are event-driven technologies!

    In programming there are three basic types of elements: methods (including functions and subroutines), properties, and events.  You’re already familiar with the first two.  We use those every day.

    An event typically has two parts: an event method and an event sink.  We make a call to the event method to start the process off.  The method wants to know if a particular event occurs so it drops an event sink in memory.

    Think of the event sink like a Boolean flag.  It has an initial value of False (i.e. the event hasn’t happened yet).  The sink then waits in memory until the event occurs.  At this point you can consider it to be True.

    The event method checks back with the event sink periodically until either the event has occurred or until the request times out.  It then returns a value indicating its exit code.

    Okay, so it’s actually more detailed than that, but you get the idea.

    Since VBScript is an event-driven language, events are actually very important to VBScript’s functionality.  Unfortunately for us, very few events are directly available to us within the WSH environment.  That’s different with WMI, however.

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


       · Teach your scripts how to react in response to their environment!
     

    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 3 Hosted by Hostway
    Stay green...Green IT