| | |
CPU Temp in VB.net?
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
the idea of what i want to do is to display the cpu temperature in a label that will refresh through a timer. i have search several sites including this one that do have the code and how to do it, but then my problem is that several items are not declared and have no clue how to declare them?
most of the code being something similar to this
but then the things that are not declared are
*ManagementObjectSearcher
*ManagementObject
*ManagementException
I honestly have no idea what to do with this anyway!
Im assuming it is completely possible to get the temp somehow, maybe not in vb but maybe something else, because i am currently running "Core Temp"
hopefully this makes since to someone other than me!
if you can i'd appreciate the help!
most of the code being something similar to this
but then the things that are not declared are
*ManagementObjectSearcher
*ManagementObject
*ManagementException
VB.NET Syntax (Toggle Plain Text)
Try Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature") For Each queryObj As ManagementObject In searcher.Get() Dim temp As Double = CDbl(queryObj("CurrentTemperature")) temp = (temp - 2732) / 10.0 MessageBox.Show(temp.ToString) Next Catch ex As ManagementException MessageBox.Show(ex.Message) End Try
I honestly have no idea what to do with this anyway!
Im assuming it is completely possible to get the temp somehow, maybe not in vb but maybe something else, because i am currently running "Core Temp"
hopefully this makes since to someone other than me!
if you can i'd appreciate the help!
1- You had to add this line in top of the form
Imports System.Management
2- Add refrence for System.Management
Imports System.Management
2- Add refrence for System.Management
Show what? the temperature result?
All I did is copy/paste your code, add the reference as I mention to you, and run the form, and it give me "not supported"
So I guess the code is working some some hardware.
Did you manage to run the code?
All I did is copy/paste your code, add the reference as I mention to you, and run the form, and it give me "not supported"
So I guess the code is working some some hardware.
Did you manage to run the code?
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
- Make a new form
- Add reference to the system.management that is:
a) right click on your project solution file
b) go to add reference, you will be taken to a window where first tab is com component
c) scroll down to system.management
d) press OK - Add a label from the toolbox
- Add a button from the toolbox
copy paste the following code:
VB.NET Syntax (Toggle Plain Text)
Imports System Imports System.Management Public Class frmMain Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature") For Each queryObj As ManagementObject In searcher.Get() Dim temp As Double = CDbl(queryObj("CurrentTemperature")) temp = (temp - 2732) / 10.0 MessageBox.Show(temp.ToString) Next Catch ex As ManagementException MessageBox.Show(ex.Message) End Try End Sub End Class
NOTE: this code will only run if your running windows XP or maybe vista & you need to have administrative rights on the machine.
Regards.
Share your knowledge It's one way to achieve immortality.
My Blog: http://blog.rabihtawil.com
My Programming Community: http://www.coderisland.com
My Blog: http://blog.rabihtawil.com
My Programming Community: http://www.coderisland.com
Ok, so here's what i have now
I've tweaked it to show in Fahrenheit
But, it only shows 2 values
and every time the button is clicked it only shows those same 2 values
is there something being done wrong or is this just how it is?
oh and i tried sending it to a label by putting
instead of
but the label only showed one value instead of the 2
and it was always the same
is there any way i could get the 'current' value(s) and display them separately?
preferably in a label or 2
VB.NET Syntax (Toggle Plain Text)
Imports System Imports System.Management Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature") For Each queryObj As ManagementObject In searcher.Get() Dim temp As Double = CDbl(queryObj("CurrentTemperature")) temp = (((temp / 10) - 273.15) * 1.8) + 32 MessageBox.Show(temp.ToString) Next Catch ex As ManagementException MessageBox.Show(ex.Message) End Try End Sub End Class
But, it only shows 2 values
and every time the button is clicked it only shows those same 2 values
is there something being done wrong or is this just how it is?
oh and i tried sending it to a label by putting
VB.NET Syntax (Toggle Plain Text)
label1.text "" & temp.ToString & ""
VB.NET Syntax (Toggle Plain Text)
MessageBox.Show(temp.ToString)
and it was always the same
is there any way i could get the 'current' value(s) and display them separately?
preferably in a label or 2
Last edited by Smalls; Sep 24th, 2009 at 5:13 am. Reason: change in spacing - OCD
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
•
•
•
•
Ok, so here's what i have now
I've tweaked it to show in FahrenheitVB.NET Syntax (Toggle Plain Text)
Imports System Imports System.Management Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature") For Each queryObj As ManagementObject In searcher.Get() Dim temp As Double = CDbl(queryObj("CurrentTemperature")) temp = (((temp / 10) - 273.15) * 1.8) + 32 MessageBox.Show(temp.ToString) Next Catch ex As ManagementException MessageBox.Show(ex.Message) End Try End Sub End Class
But, it only shows 2 values
and every time the button is clicked it only shows those same 2 values
is there something being done wrong or is this just how it is?
oh and i tried sending it to a label by putting
instead ofVB.NET Syntax (Toggle Plain Text)
label1.text "" & temp.ToString & ""
but the label only showed one value instead of the 2VB.NET Syntax (Toggle Plain Text)
MessageBox.Show(temp.ToString)
and it was always the same
is there any way i could get the 'current' value(s) and display them separately?
preferably in a label or 2
Thanks for using my code

you should put a timer & put the code block in a function make that timer call the function every one second & your values will get refreshed every 1 second.
yes you can get the values into 2 different labels you can use substring functions, so u take a part of the function to the first label & another to the second label.
if you need help coding that, you just ask!
regards.
Share your knowledge It's one way to achieve immortality.
My Blog: http://blog.rabihtawil.com
My Programming Community: http://www.coderisland.com
My Blog: http://blog.rabihtawil.com
My Programming Community: http://www.coderisland.com
I'm not to sure on how to get them into 2 labels using sub-strings?
but also, from what i see the values are not getting refreshed, the only 2 values I'm getting are 134.69 and 123.89
and why would there be that big of a difference, Core Temp never shows that big of difference, nor are the values the same as core temp?
I'm just sort of curious, what are these numbers from and why are they so different?
but also, from what i see the values are not getting refreshed, the only 2 values I'm getting are 134.69 and 123.89
and why would there be that big of a difference, Core Temp never shows that big of difference, nor are the values the same as core temp?
I'm just sort of curious, what are these numbers from and why are they so different?
![]() |
Similar Threads
- 100C CPU Temp! (Motherboards, CPUs and RAM)
- CPU over temp, newly build computer (Motherboards, CPUs and RAM)
- weird cpu temp. (Motherboards, CPUs and RAM)
- CPU Temp to high (Windows NT / 2000 / XP)
- CPU TEMP. Display (Cellphones, PDAs and Handheld Devices)
- Monitoring CPU Temp (Motherboards, CPUs and RAM)
- CPU temp monitoring (Motherboards, CPUs and RAM)
- cpu temp. (Motherboards, CPUs and RAM)
Other Threads in the VB.NET Forum
- Previous Thread: System.InvalidOperationException
- Next Thread: Autocomplete ComboBox not by the first letter?
| Thread Tools | Search this Thread |
100mbs acquisitions aig amd apple arm atom ballmer bartz beep blog broadcom buffett centrino china chips chipset conversion core core2quad corporateearnings cpu cray ctscomputers development digitaltv fastest flash gaming geithner globalfoundry google gpu graphics hardware highperformancecomputing hp ibm imflash intel internet iphone larrabee layoffs linux memory microprocessors microsoft motherboard multicore nand news node nvidia oakmontfund obama opengl operatingsystems otellini overheat pcm pentiumm pfizer playstation playstation3 pram processor processors quad ram rdimm researchinmotion rss schumer semiconductors servers shortselling software solidstatedrive specification speed sprint stocks supercomputer supply technology technologystocks techstocks temp temperature tesla upgrade usb web wiki windows wirelesselectricity witricity xeon yahoo







