How to

enumerate computer temperature sensors

Published: 12. February 2012 | Updated: 12. February 2012
License: Microsoft Public License (MS-PL)
Categories: Windows » Hardware
Tags: C# Hardware Windows WMI
Was this snippet helpful for you? YESYES / NONO

Snippet example shows how to enumerate computer temperature sensors / electronic thermometers.

Import namespaces

using System;
using System.Collections.Generic;
using System.Management; // requires adding System.Management reference to project

Code

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_TemperatureProbe");
ManagementObjectCollection collection = searcher.Get();

var items = new List<Win32_TemperatureProbe>();
foreach (ManagementObject obj in collection)
{
    var item = new Win32_TemperatureProbe();
    item.Accuracy = (int?)obj["Accuracy"];
    item.Availability = (ushort?)obj["Availability"];
    item.Caption = (string)obj["Caption"];
    item.ConfigManagerErrorCode = (uint?)obj["ConfigManagerErrorCode"];
    item.ConfigManagerUserConfig = (bool?)obj["ConfigManagerUserConfig"];
    item.CreationClassName = (string)obj["CreationClassName"];
    item.CurrentReading = (int?)obj["CurrentReading"];
    item.Description = (string)obj["Description"];
    item.DeviceID = (string)obj["DeviceID"];
    item.ErrorCleared = (bool?)obj["ErrorCleared"];
    item.ErrorDescription = (string)obj["ErrorDescription"];
    item.InstallDate = (DateTime?)obj["InstallDate"];
    item.IsLinear = (bool?)obj["IsLinear"];
    item.LastErrorCode = (uint?)obj["LastErrorCode"];
    item.LowerThresholdCritical = (int?)obj["LowerThresholdCritical"];
    item.LowerThresholdFatal = (int?)obj["LowerThresholdFatal"];
    item.LowerThresholdNonCritical = (int?)obj["LowerThresholdNonCritical"];
    item.MaxReadable = (int?)obj["MaxReadable"];
    item.MinReadable = (int?)obj["MinReadable"];
    item.Name = (string)obj["Name"];
    item.NominalReading = (int?)obj["NominalReading"];
    item.NormalMax = (int?)obj["NormalMax"];
    item.NormalMin = (int?)obj["NormalMin"];
    item.PNPDeviceID = (string)obj["PNPDeviceID"];
    item.PowerManagementCapabilities = (ushort[])obj["PowerManagementCapabilities"];
    item.PowerManagementSupported = (bool?)obj["PowerManagementSupported"];
    item.Resolution = (uint?)obj["Resolution"];
    item.Status = (string)obj["Status"];
    item.StatusInfo = (ushort?)obj["StatusInfo"];
    item.SystemCreationClassName = (string)obj["SystemCreationClassName"];
    item.SystemName = (string)obj["SystemName"];
    item.Tolerance = (int?)obj["Tolerance"];
    item.UpperThresholdCritical = (int?)obj["UpperThresholdCritical"];
    item.UpperThresholdFatal = (int?)obj["UpperThresholdFatal"];
    item.UpperThresholdNonCritical = (int?)obj["UpperThresholdNonCritical"];

    items.Add(item);
}

Class

public class Win32_TemperatureProbe
{
    public int? Accuracy;
    public ushort? Availability;
    public string Caption;
    public uint? ConfigManagerErrorCode;
    public bool? ConfigManagerUserConfig;
    public string CreationClassName;
    public int? CurrentReading;
    public string Description;
    public string DeviceID;
    public bool? ErrorCleared;
    public string ErrorDescription;
    public DateTime? InstallDate;
    public bool? IsLinear;
    public uint? LastErrorCode;
    public int? LowerThresholdCritical;
    public int? LowerThresholdFatal;
    public int? LowerThresholdNonCritical;
    public int? MaxReadable;
    public int? MinReadable;
    public string Name;
    public int? NominalReading;
    public int? NormalMax;
    public int? NormalMin;
    public string PNPDeviceID;
    public ushort[] PowerManagementCapabilities;
    public bool? PowerManagementSupported;
    public uint? Resolution;
    public string Status;
    public ushort? StatusInfo;
    public string SystemCreationClassName;
    public string SystemName;
    public int? Tolerance;
    public int? UpperThresholdCritical;
    public int? UpperThresholdFatal;
    public int? UpperThresholdNonCritical;
}
Send us feedback about this snippet »



Related Snippets: