WMI Programming with Visual Basic.NET: Managing the OS, continued (Page 1 of 6 )
In my previous article, part three of this series, we looked at some examples of accessing OS and hardware related information through WMI and VB.NET. In this article, we will look into managing the OS using WMI methods.
You can download the zip of the 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 scratch. It will not be repeated anymore in any of the future articles in this series.
Can we operate (or manage) using WMI classes?
In all of the previous parts of this series, I mostly concentrated on retrieving information (locally or remotely). We didn’t operate (or manage) that information. We just fetched and displayed the information on the form.
Certain classes of WMI provide some methods for operating on WMI objects. I should admit that we will not be able to do each and every operation that WIN32 API does. But, mostly we can serve our needs just by using WMI (instead of complicating ourselves with WIN32 API).
Since we now understand that we can manage the Windows operating system using some WMI objects, we need to know a bit of theory about its implementation. All of my examples (in previous parts of this series) until now were working only with certain properties of the respective WMI class. But, some of the WMI classes were already designed with certain methods to operate on the respective objects. To invoke those methods programmatically, the class “ManagementObject” exposes a method called “InvokeMethod.” Using this method, we can call any method of any WMI class (which has methods to execute) programmatically.
Whenever a method gets executed dynamically (programmatically), we should certainly check (in general) for its result (whether executed successfully or not). When any WMI methods gets executed through “InvokeMethod”, it returns an object of type “ManagementBaseObject”, which contains all of the parameters sent out (in this case return values or returned properties). We can know the status of the WMI method execution through this object easily by fetching its properties (or return values).
I don’t want to discourage you with only theory. The following sections will show you the practical implementation of the theory stated above.
Next: Retrieving the list of all services >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee