Gets the current temp of the CPU

0

Category:

    '''


    ''' Specifies the format the temp should be returned in
    '''

    Public Enum TempFormat
        Fahrenheit
        Celsius
        Kelvin
        '''
        ''' The CPU temp will be returned in it's raw, uncalculated format
        '''

        Raw
    End Enum
    '''
    ''' Gets the current temp of the CPU
    '''

    '''
The temp scale the value should be returned in
    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

Comments (0)

Post a Comment

Copyright © 2009 virtualinfocom All rights reserved. Theme by Games. | animation Ani2Pix.