CPU Temp in VB.net?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 58
Reputation: Smalls is an unknown quantity at this point 
Solved Threads: 2
Smalls's Avatar
Smalls Smalls is offline Offline
Junior Poster in Training

CPU Temp in VB.net?

 
0
  #1
Sep 15th, 2009
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

  1. Try
  2. Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
  3. For Each queryObj As ManagementObject In searcher.Get()
  4. Dim temp As Double = CDbl(queryObj("CurrentTemperature"))
  5. temp = (temp - 2732) / 10.0
  6. MessageBox.Show(temp.ToString)
  7. Next
  8. Catch ex As ManagementException
  9. MessageBox.Show(ex.Message)
  10. 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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 148
Reputation: samir_ibrahim is on a distinguished road 
Solved Threads: 16
samir_ibrahim's Avatar
samir_ibrahim samir_ibrahim is offline Offline
Junior Poster

Re: CPU Temp in VB.net?

 
0
  #2
Sep 17th, 2009
1- You had to add this line in top of the form
Imports System.Management

2- Add refrence for System.Management
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 58
Reputation: Smalls is an unknown quantity at this point 
Solved Threads: 2
Smalls's Avatar
Smalls Smalls is offline Offline
Junior Poster in Training

Re: CPU Temp in VB.net?

 
0
  #3
Sep 17th, 2009
But, how do i actually get it to show?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,666
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 476
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: CPU Temp in VB.net?

 
0
  #4
Sep 17th, 2009
Take a look at Thread
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 148
Reputation: samir_ibrahim is on a distinguished road 
Solved Threads: 16
samir_ibrahim's Avatar
samir_ibrahim samir_ibrahim is offline Offline
Junior Poster

Re: CPU Temp in VB.net?

 
0
  #5
Sep 18th, 2009
Originally Posted by Smalls View Post
But, how do i actually get it to show?
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 19
Reputation: raymyster has a little shameless behaviour in the past 
Solved Threads: 0
raymyster raymyster is offline Offline
Newbie Poster

Re: CPU Temp in VB.net?

 
0
  #6
Sep 19th, 2009
  1. Make a new form
  2. 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
  3. Add a label from the toolbox
  4. Add a button from the toolbox

copy paste the following code:
  1. Imports System
  2. Imports System.Management
  3.  
  4. Public Class frmMain
  5.  
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7. Try
  8. Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
  9.  
  10. For Each queryObj As ManagementObject In searcher.Get()
  11. Dim temp As Double = CDbl(queryObj("CurrentTemperature"))
  12. temp = (temp - 2732) / 10.0
  13. MessageBox.Show(temp.ToString)
  14. Next
  15.  
  16. Catch ex As ManagementException
  17. MessageBox.Show(ex.Message)
  18. End Try
  19.  
  20. End Sub
  21.  
  22. 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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 58
Reputation: Smalls is an unknown quantity at this point 
Solved Threads: 2
Smalls's Avatar
Smalls Smalls is offline Offline
Junior Poster in Training

Re: CPU Temp in VB.net?

 
0
  #7
Sep 24th, 2009
Ok, so here's what i have now
  1. Imports System
  2. Imports System.Management
  3.  
  4. Public Class Form1
  5.  
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7. Try
  8. Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
  9. For Each queryObj As ManagementObject In searcher.Get()
  10. Dim temp As Double = CDbl(queryObj("CurrentTemperature"))
  11. temp = (((temp / 10) - 273.15) * 1.8) + 32
  12.  
  13. MessageBox.Show(temp.ToString)
  14. Next
  15. Catch ex As ManagementException
  16. MessageBox.Show(ex.Message)
  17. End Try
  18.  
  19.  
  20. End Sub
  21. End Class
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
  1. label1.text "" & temp.ToString & ""
instead of
  1. MessageBox.Show(temp.ToString)
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
Last edited by Smalls; Sep 24th, 2009 at 5:13 am. Reason: change in spacing - OCD
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 19
Reputation: raymyster has a little shameless behaviour in the past 
Solved Threads: 0
raymyster raymyster is offline Offline
Newbie Poster

Re: CPU Temp in VB.net?

 
0
  #8
Sep 24th, 2009
Originally Posted by Smalls View Post
Ok, so here's what i have now
  1. Imports System
  2. Imports System.Management
  3.  
  4. Public Class Form1
  5.  
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7. Try
  8. Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
  9. For Each queryObj As ManagementObject In searcher.Get()
  10. Dim temp As Double = CDbl(queryObj("CurrentTemperature"))
  11. temp = (((temp / 10) - 273.15) * 1.8) + 32
  12.  
  13. MessageBox.Show(temp.ToString)
  14. Next
  15. Catch ex As ManagementException
  16. MessageBox.Show(ex.Message)
  17. End Try
  18.  
  19.  
  20. End Sub
  21. End Class
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
  1. label1.text "" & temp.ToString & ""
instead of
  1. MessageBox.Show(temp.ToString)
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

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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 58
Reputation: Smalls is an unknown quantity at this point 
Solved Threads: 2
Smalls's Avatar
Smalls Smalls is offline Offline
Junior Poster in Training

Re: CPU Temp in VB.net?

 
0
  #9
Sep 24th, 2009
I'm not real sure on how to do that could you show me?

also, from what i've seen, the values are always the same.
shouldn't it be that every time you click the button , the app goes and gets fresh values?
Last edited by Smalls; Sep 24th, 2009 at 11:31 pm. Reason: typo
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 58
Reputation: Smalls is an unknown quantity at this point 
Solved Threads: 2
Smalls's Avatar
Smalls Smalls is offline Offline
Junior Poster in Training

Re: CPU Temp in VB.net?

 
0
  #10
Sep 28th, 2009
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?
Reply With Quote Quick reply to this message  
Reply

Tags
cpu, intel, temp, temperature

Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC