Easy access to system information in. NET (1)-wmi article Montaque (original)
Key word Wmi,wql,managementobjectsearcher
Easy access to system information in. NET (1)-WMI article
Montaque
Statement:
1, a little personal experience, for reference only
2, reprint time, please reserve original.
Overview:
Do not know if you have this experience? Sometimes to get a little bit of information about the system, consider the version number of the operating system, or the resolution of the current screen. In fact, the bottom line is to read a certain aspect of the operating system of a property value, and then see our program in the dense WIN32 API declarations, calls, code readability and maintenance of self-evident. To. NET, Microsoft offers a richer class, and many of the methods used to invoke the API can be easily invoked in. Net. Today a brief introduction is in. NET for the purpose of obtaining information through communication with WMI (Windows Management specification).
Main ideas:
For an example of obtaining the operating system shared directory and obtaining the motherboard number, this article describes how to obtain system-related information using the classes below system.managment:
Body:
WMI (Windows Management Specification: Windows Management Instrumentation) is the implementation of Microsoft's Web-based Enterprise Management (WBEM) and is also a standards-based system management interface. WMI first appears on a Microsoft Windows 2000 system, but it can also be installed on Windows NT 4 and Windows 9x computers. WMI is a powerful tool for easy access to system information.
In. NET, there is a system.management name space (the system defaults to no reference, we can manually add a reference), through the following class operation, you can query the system software and hardware information, first look at a simple example:
Imports System.Management
Dim Searcher as New managementobjectsearcher ("SELECT * from Win32_Share")
Dim Share as ManagementObject
For each share in searcher. Get ()
MessageBox.Show (share. GetText (Textformat.mof))
Next Share
The result of the run is a list of directories that are currently shared by all systems, as well as descriptions, and so on.
Analysis of the above code, you can see a few:
1, seems to be in the database operation, a bit like SQL statements. In fact, the SQL operation, the statement is WQL (WMI Query Language), is actually a subset of standard SQL plus the extension of WMI.
2, WQL is a read-only query language, we can only query the response data, can not use Update,insert and other update operations
3, the code is very simple, easy to understand
4, we use a MOF (Managed Object format) display.
Example two: Get information on the current motherboard
The above example is a software aspect of information, look at a sample of hardware information to obtain the motherboard serial number and manufacturer:
Dim Searcher as New managementobjectsearcher ("SELECT * from Win32_baseboard")
WMI classes are also layered, referring to WMI in MSDN; NET platform development, it is best to read more about. NET new features, which can greatly improve the development efficiency of the Code and the running efficiency. <
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.