Event Scripting with WMI - Introduction to WMI
(Page 2 of 4 )
WMI provides a few basic events that, when used properly, can be very useful. Take for example the __InstanceCreationEvent. This event allows us to know when something gets created.
Okay, so what is something? Well, simply put—whatever we want to watch. Maybe we want to know when a file is created. Or perhaps we’d like to know when a new key is added to the registry. How about knowing when a program starts?
All right, I’m getting a little carried away. Let’s take this slowly and look at an example. We’re going to wait for a file to be created and then delete it. Why? Because it’s a pointless example, that’s why.
I’m going to assume you’ve worked with WMI to some extent before. If you haven’t, you’ve probably at least seen it. If not, well, just try to keep up. It looks intimidating but it’s really not that bad.
WMI consists of a series of classes that contain information about the environment. Some of them are intrinsic classes, native to WMI, and some are made available by other Providers. All you really need to understand at this point is that WMI functions somewhat like a database. All interactions take the form of queries.
If you know any form of SQL you will find this very easy. The specific variation used by WMI is known as WQL.
We begin our script by connecting to the WMI service with the cimv2 provider. This part should be a snap for you at this point.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & strComputer _
& "rootcimv2")
Next: Using __InstanceCreationEvent >>
More Windows Scripting Articles
More By Nilpo/Developer Shed Staff Writer