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

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    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

    - 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

    IBM developerWorks




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