WMI Programming with Visual Basic.NET: Managing the OS (Page 1 of 6 )
In my previous article, part two of this series, we looked through some examples for 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 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 operate (or manage) using WMI classes?
In the previous parts of this series, I mostly concentrated on retrieving information (locally or remotely). Actually we didn’t operate (or manage) with 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 the WIN32 API does. But, mostly we can serve our needs just by using WMI (instead of complicating the situation with WIN32 API).
Since we now understand that we can manage the Windows operating system by using some of WMI objects, we need to know a bit about the theory of its implementation. All of my examples (in previous parts of this series) up to now worked 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 it executed successfully or not. When any WMI method 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 just fetching its properties (or return values).
I don’t want to discourage you with by focusing only on 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