01-20-2012، 01:07 PM
Get the CPU temperature
Not just Celsius and Fahrenheit, but Kelvin too.
Not just Celsius and Fahrenheit, but Kelvin too.
سورس کد :
کد پیاچپی:
''' <summary>
''' Specifies the format the temp should be returned in
''' </summary>
Public Enum TempFormat
Fahrenheit
Celsius
Kelvin
''' <summary>
''' The CPU temp will be returned in it's raw, uncalculated format
''' </summary>
Raw
End Enum
''' <summary>
''' Gets the current temp of the CPU
''' </summary>
''' <param name="Format">The temp scale the value should be returned in</param>
Public Function GetCPUTemp(ByVal Format As TempFormat) As Single
Dim enumerator As System.Management.ManagementObjectCollection.ManagementObjectEnumerator
Dim searcher As New System.Management.ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
enumerator = searcher.Get.GetEnumerator()
While enumerator.MoveNext
Dim obj As System.Management.ManagementObject = CType(enumerator.Current, System.Management.ManagementObject)
Select Case format
Case TempFormat.Fahrenheit
Return CSng((obj.Item("CurrentTemperature") / 10 - 273.15) * 9 / 5 + 32)
Case TempFormat.Celsius
Return CSng(obj.Item("CurrentTemperature") / 10 - 273.15)
Case TempFormat.Kelvin
Return CSng(obj.Item("CurrentTemperature") / 10)
Case TempFormat.Raw
Return CSng(obj.Item("CurrentTemperature"))
End Select
End While
End Function