WMI and WQL Learning

Source: Internet
Author: User
Tags foreach tostring

Basics: WMI is a core Windows management technology that allows users to manage local and remote computers using WMI. WQL is the query language in WMI and can be translated into Chinese as a Windows Management specification query language.

1. How to get the temperature and model of the CPU

Because Windows itself does not provide a way to monitor the temperature, WMI, though it is the administrative service provided by Windows, still requires hardware support to get the information it needs.

Msacpi_thermalzonetemperature, as the name implies, is queried through the common management interface of ACPI, so your system must have an ACPI hot zone to ask, and the ACPI hot zone is actually a notebook design product, The design of the ACPI Hot zone is not in the PC system.

Generally on the computer is the use of Win32_temperatureprobe to query, but because Win32_temperatureprobe is directly asked Smbios, from the smbios inside dug up the data, but smbios whether there is support for WMI is determined by the motherboard manufacturer. That is, if the motherboard manufacturer has support for WMI, it can read the CPU temperature using Win32_temperatureprobe's currentreading. Unfortunately, most (almost all) motherboard vendors do not support this feature.

WMI's Windows Management specification provides systems, appliances, and application information to obtain WMI messages in the System.Management namespaces provided in. NET, which describes how to obtain the temperature and serial number of the CPU.

Using the ManagementObjectSearcher object class, you must first add the System.Management to the reference before you use it

private void Getcputemperature ()
        {
            double cputprt = 0;
            System.Management.ManagementObjectSearcher mos
                = new System.Management.ManagementObjectSearcher (@ "Root\wmi", " Select * from Msacpi_thermalzonetemperature ");
    
            foreach (System.Management.ManagementObject mo in MoS. Get ())
            {
                cputprt = convert.todouble (convert.todouble (MO). GetPropertyValue ("Crrenttemperature"). ToString ())-2732)/ten;
                Label1. Text = "CPU temperature:" + cputprt.tostring () + "°c\n";
            }
        }
    
        private void Getcpucode ()
        {
            ManagementObjectSearcher moSearch = new ManagementObjectSearcher ("SELECT * FROM Win32_Processor ");
    
            foreach (ManagementObject mobject in Mosearch.get ())
            {
                this.label1.text+= (mobject["Processorid"]. ToString ());
            }
        

2.WQL knowledge

WQL is the query language in WMI, WQL's full name is WMI query Language, referred to as WQL, translated into Chinese as if it could be the Windows Management Specification query language. A friend who is familiar with the SQL language will feel that it is very similar to SQL.

WQL is actually very simple, it has the following characteristics:

1. Each WQL statement must start with a SELECT;

2, after the SELECT and you need to query the name of the property (I just corresponding to the SQL referred to as the field name), but also like SQL, with * to return all the property values;

3, from the keyword;

4, you want to query the name of the class;

5, in addition, if you want to exact query results can also add WHERE conditional clause. For example, a class has the Enable attribute, and you can add a where enable=true to the query.

Just like this:

SELECT field name from class name

The following are the correct WQL statements:

Select * from Win32_LogicalDisk where drivetype=3 ' queries all hard disk partitions

SELECT * from Win32_Share ' Queries all shared directories

SELECT * from Win32_NetworkAdapterConfiguration WHERE dhcpenabled=true

SELECT Description from Win32_account WHERE name= ' Administrator '

SELECT Freespace,deviceid from Win32_LogicalDisk

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.