Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,273 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,251 people online right now. Registration is fast and FREE... Join Now!




CPU Tempearture

 
Reply to this topicStart new topic

CPU Tempearture

kirpat2002
14 Oct, 2008 - 01:05 AM
Post #1

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 1

CODE
Imports System.Management

Public Enum TempFormat
        Fahrenheit
        Celsius
        Kelvin
        ''' <summary>
        ''' The CPU temp will be returned in it's raw, uncalculated format
        ''' </summary>
        Raw
    End Enum


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



The above code gives an error as "Not Supported" on the movenext method. I am using XP Professional with service pack 3. If this dose'nt work could you provide me with an alternate solution to find the cpu temperature.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: CPU Tempearture
14 Oct, 2008 - 01:47 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,199



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well remember that ManagementObjectSearcher.Get() is going to return a collection, not a resultset like a database. So you would move through it like you would any listbox or any other collection. Like with for each ...

vb

For Each obj As ManagementObject In searcher.Get()
' Do something with your ManagementObject "obj"
Next


The error was telling you that the collection doesn't have a "movenext" method. This should get you unstuck. Good luck.

"At DIC we be management object hustling code ninjas... we also hustle people at the local bar pool table. Now jacobjordan, he just gets plain hustled by the ladies." decap.gif

This post has been edited by Martyr2: 14 Oct, 2008 - 01:48 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 05:03AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month