WMI namespace in the. NET Framework

Source: Internet
Author: User

In the. NET Framework, there are two namespaces related to WMI specifications: system. Management and System. Management. instrumentation. System. the class object provided by The managemen namespace provides an object-oriented programming interface for accessing various management objects. management. the entation namespace provides classes for setting custom applications so that these application objects can comply with WMI specifications, in this way, WMI is used to disclose the management information and events provided by the Application Manager. These users may be Microsoft Application Center or Microsoft Operations Manager, it may also be a custom high-end management application (you can use the system. manage the class objects provided by the namespace to compile your own management applications ). Therefore, if you want to manage your products, you have to make your applications comply with WMI specifications. for the WMI specification compilation of applications on the net platform, the system is used. management. the class provided by the instrumentation namespace.
System. Management namespace
The system. Management namespace is the WMI namespace in. NET Framework. This namespace includes the following important class objects:
Managementclass: management class. Its constructor input parameter is the WMI class name, which identifies the management object, for example:
Diskman = new managementclass ("win32_logicaldisk ");
Diskman is the management object of the entire Logical Disk On the Win32 platform.
Managementobjectcollection: a collection of managementobject management objects.
Managementobject and: managementobject are specific data management objects. For the above example, they can correspond to the C partition management object of the Logical Disk. See the following code:
**************************************** *************
Managementobjectcollection disks = diskman. getinstances ();
Foreach (managementobject disk in disks)
{

Console. writeline ("disk = {0}", disk ["name"]. tostring ());

Console. writeline ("disk = {0}", disk ["filesystem"]. tostring ());

Console. writeline ("disk = {0}", disk ["size"]. tostring ());

}
**************************************** *************
Disks is the logical disk partition C, D, E... For each logical partition, a disk object manages its data and outputs the name, file system, and disk space.
Managementquery: Used as the basis for all query classes. As mentioned earlier, for management objects, you can filter and query data that you are interested in like using SQL query statements in relational databases, such:
Select * From Win32 _ logicaldisk
As the abstract base class of the query, managementquery can be inherited to implement its method. selectquery is.
Managementobjectsearcher: used to retrieve and manage the collection of objects based on the specified query or enumeration.
**************************************** *************
Selectquery = new selectquery ("win32_logicaldisk ");
Managementobjectsearcher searcher =

New managementobjectsearcher (selectquery );

Foreach (managementobject disk in searcher. Get ())

{

Console. writeline (disk. tostring ());

}
**************************************** ************

The code above specifies that the searcher query is selectquery, that is, a collection query of Win32 logical disks, and then outputs these Logical Disk Partitions. You can also use the SQL query statement to instantiate the managementobjectsearcher object. The Code is as follows:
Managementobjectsearcher search = new managementobjectsearcher ("select * From Win32 _ logicaldisk
");

Managementeventwatcher: Used to schedule WMI event notifications, which will be detailed in later sections.
Other classes in this namespace will be described in the subsequent examples.
System. Management. instrumentation namespace
From the content described above, you should know that if you want to enable your own applications or products to use management tools such as Microsoft Application Center or Microsoft Operations Manager, you should expose your application objects to tools that support WMI. The class provided by the system. Management. instrumentation namespace is used.
The system. Management. instrumentation namespace allows you to easily complete the following tasks:
Standardize applications;
Expose application events as WMI events;
Creation management object;
Define and use the relationship between management objects.
Standardize the object of an application and make it conform to the WMI specification. Such work is straightforward for. Net programmers. Because the WMI architecture model is originally object-oriented and has many features that are consistent with. Net metadata. Therefore, the application objects can be directly mapped to WMI objects, which are the same, so that the application code can be converted into manageable application code at no cost. For example, you can standardize the. NET application as follows:
Application components can have events.
Provides manageable objects so that applications can be configured.
Expose runtime data, such as performance characteristics.
WMI normalization of. NET applications is better explained, and how to access management objects in applications in windows and web-based programs is provided.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.