WMI Programming with Visual Basic.NET: Trapping System Events (Page 1 of 4 )
In my previous article, part five of this series, we looked at some tips and tricks for using WMI. In this article we will focus on working with trapping system events through WMI.
You can download the zip of entire Visual Studio.NET solution (developed for this article)
here.
The first part of my series gives you the details for creating a Visual Studio.NET solution for WMI, right from the scratch. It will not be repeated any more in any of the future articles in this series.
Can we trap system events through WMI?
In parts four and five, we looked at managing Windows OS using WMI. We used to call methods of the respective WMI class according to our needs. Trapping system events is also a part of managing the Windows OS. For example, all Performance Counters can be considered as event trappers of their respective events.
The answer to the above question is “yes.” We can trap system events using WMI as our main interface. Before WMI (and even now), we needed to trap those events only through the WIN32 API. Most probably, Microsoft Visual C++ is a very flexible tool for working with the WIN32 API, as the entire WIN32 API was developed through the same language (but is difficult to understand). There is no wonder that the entire Windows OS was developed using Microsoft Visual C++.
This article focuses on working with “trapping events” using WMI and Visual Basic.NET as core technologies. This is a bit of an advanced topic in WMI. Even though it is bit difficult to understand, try your best to follow.
As you recall from part two of my series, I explained the “types of WQL queries." But I didn’t say much about “Event Queries” in that article. In this article, I will introduce that concept, and we will implement it.
Let us discuss what an “event” in the Windows OS actually is. Every programmer knows that the entire Windows OS is event-driven. Anything you operate with the Windows OS is an event. Examples of events include, but are not limited to, logging in, logging out, printing a page, installing software, opening an application, connecting to a network, stopping and starting system services, and so forth.
Now, say I wanted to have some script executed (such as starting an application) when someone logs in. That means my script should register to the “login” event, and continuously listen for that event to occur. When the event occurs, my script gets executed. These types of scripts (listening for events of WMI) are called consumers. Consumers use “Event queries” to register and receive notification of events. Event providers use event queries to register (and of course listen for) one or more events. In general, the queries used for trapping event notifications are called “event queries.”
Next: Creating a simple application >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee