473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to Get HardWare Information from CPU like Temparature,Voltage,FanSpeed. code in .

I was using This Code...
//---Code---//
Expand|Select|Wrap|Line Numbers
  1.             ManagementObjectSearcher mySearcher = new ManagementObjectSearcher("root\\WMI","SELECT * from Win32_TemparatureProbe");          
  2.  
  3.  
  4.             foreach (ManagementBaseObject obj in mySearcher.Get())
  5.             {
  6.  
  7.                 if (obj == null)
  8.                 {
  9.                     label1.Text = "didn't find";
  10.                 }
  11.                 else
  12.                 {
  13.                     label1.Text = obj["Accuracy"].ToString ();
  14.                 }
  15.  
  16.             }
  17.  
//---Code End---//

But No RESULT.

Plz me code for How to Get HardWare Information from CPU like Temparature,Voltage,FanSpeed. code in .Net

Thanks
Aug 8 '08 #1
16 10761
pootle
68
One obvious thing wrong - you have mis-spelt the WMI class name - it is "Win32_TemperatureProbe" (Tempe not Tempa).

For information about the temperature probe, check out:
http://msdn.microsoft.com/en-us/library/aa394493(VS.85).aspx

There is also a Win32_Fan class for fan speed (not sure if this is what you want...):
http://msdn.microsoft.com/en-us/library/aa394146(VS.85).aspx

And also a Win32_Processor for CPU voltage:
http://msdn.microsoft.com/en-us/library/aa394373(VS.85).aspx

HTH
Aug 8 '08 #2
Plater
7,872 Expert 4TB
Win32_TemperatureProbe is under root\CIMV2 not root\WMI
I was very interested in this for awhile, until I discovered that my Dell desktop does not contain any accessible temp probes. It contains ONE fan and one harddrive temp(which if anyone knows how to get at the harddrive temp, I would love to hear it)
Aug 8 '08 #3
joedeene
583 512MB
Win32_TemperatureProbe is under root\CIMV2 not root\WMI
I was very interested in this for awhile, until I discovered that my Dell desktop does not contain any accessible temp probes. It contains ONE fan and one harddrive temp(which if anyone knows how to get at the harddrive temp, I would love to hear it)

NOTE: This code is only tested on my Western Digital 120GB hard drive, and may not work on others! Also, you need to add System.Management as a reference (right-click on WindowsApplication1 and choose Add Reference)


*** Not my code
Expand|Select|Wrap|Line Numbers
  1. Imports System
  2.  
  3. Imports System.Management
  4.  
  5. Imports System.Windows.Forms
  6.  
  7. Public Class Form1
  8.  
  9.  
  10.  
  11. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.  
  13. Try
  14.  
  15. Dim searcher As New ManagementObjectSearcher( _
  16.  
  17. "root\WMI", _
  18.  
  19. "SELECT * FROM MSStorageDriver_ATAPISmartData")
  20.  
  21. For Each queryObj As ManagementObject In searcher.Get()
  22.  
  23. Dim arrVendorSpecific As Byte() = queryObj("VendorSpecific")
  24.  
  25. MsgBox("Temperature = " & arrVendorSpecific(115))
  26.  
  27. Next
  28.  
  29. Catch err As ManagementException
  30.  
  31. MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
  32.  
  33. End Try
  34.  
  35. End Sub
  36.  
  37. End Class
this oughta do it, its not my code but i tried it, and i get the error "An error occurred while querying for WMI data: Access Denied" I dont get it, i am the administrator on my laptop
Aug 8 '08 #4
Plater
7,872 Expert 4TB
I was able to get a value of "31". I am going to guess that that is in degrees C.
thanks for the good find!
Aug 8 '08 #5
joedeene
583 512MB
no problem, but could u suggest a way that i can get it to work for me? like it says access denied, where the err.message is, when the msgbox pops up. i mean i am an admin
Aug 8 '08 #6
Plater
7,872 Expert 4TB
Are you sure you are an admin and not just a power user or something?
I had no trouble running it (once the two typos were corrected)
Maybe you can google admin priveldges for WMI? Maybe there is some setting somewhere that has to be checked to allow you to use it.
You're not doing it in a web application right?


Also, in your foreach loop, obj will never be null
Aug 8 '08 #7
joedeene
583 512MB
yes, there are only two accounts on my laptop, and the main administrator(default) for like safe mode, and than mine which i just double checked is an administrator also, i'm running vista, and what typos do u mean, could i see the exact code you run when all goes successful? and then i'll try and debug it on mine, and no im not online app, i am debugging straight from visual basic 2008 express edition
Aug 8 '08 #8
Plater
7,872 Expert 4TB
EDIT: Oops, I was thinking about the OPs original code not what you had posted. What you had worked fine for me.

And I would say that it's a vista thing. I'm on XP pro. Vista has different security. You will probably need to google "vista WMI security in .NET" or something. It might just be that the .NET CLR doesn't have the correct security settings for the local zone to use WMI?
Aug 8 '08 #9
Curtis Rutland
3,256 Expert 2GB
Vista does have a different security model. You will need to "run as administrator" even if you already have an administrator account. Kind of like "sudo" in linux.

So, I think for debugging you can right-click your Visual Studio link and click "Run as Administrator"

For running the app, right click the executable. Also, there should be a setting in the shortcut's property that says something about always running as administrator.
Aug 8 '08 #10
joedeene
583 512MB
hmm, maybe its just the visual studio express debugger doesnt have permissions, because i built the application, and i right-clicked and selected run as admin and it worked, and by golley, my temp is 162, that cant be good, and i clicked it again and ran it normal just by double clicking the shortcut and it showed the message box with 162 again, so i guess its the debugger, but i shouldnt havemy temp that high, whoo =/
Aug 8 '08 #11
Curtis Rutland
3,256 Expert 2GB
Well, you can turn off UAC in Vista. Then it's just like XP...everything is run as administrator. Plus, no more popup nag screens. But that's disabling a big security feature. So, can't recommend for or against, but it's a possibility.
Aug 8 '08 #12
Plater
7,872 Expert 4TB
It's possible the 15th byte is not always the temperature one. Might be dependant on the drive manufacturer yes?
Aug 8 '08 #13
Curtis Rutland
3,256 Expert 2GB
Yeah, my output is:
Temp: 0
Temp: 237

So I doubt that one of my drives is freezing and one is boiling. Maybe that's only for the Western Digital or whatever you got this code for.
Aug 8 '08 #14
Plater
7,872 Expert 4TB
You can grab a program that already does it for you (SpeedFan is one) and compare the values it tells you for temperature and check to see which one is which in the bytes.
Aug 11 '08 #15
I received the same error.. Ordinary user with Administrator Account is not enough.. I think so..

I have Enabled the Administrator account
1. Open cmd prompt.. (Run as Administrator)
2. net user Administrator /active:yes
( Check whether Adminstrator account is already active or Not
by running command.
net user
It wil display list of users.
Administrator Guest (UrUsername)
)
3.Turn off Firewall.
..
Then try

To Activate Administrator Account see
http://www.howtogeek.com/howto/windo...windows-vista/
Jan 25 '12 #16
danp129
323 Expert 256MB
If you don't want to right-click and run-as administrator you can do this:

In your app.manifest, set the requestedExecutionLevel to this:
Expand|Select|Wrap|Line Numbers
  1.           <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
  2.  
Clean your output folder and recompile. When you open the exe it will prompt for elevated creditials.
Jan 25 '12 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Lorax | last post by:
I'm on the IS team of a medium-sized non-profit with international reach. We're trying to make some decisions regarding our Web server and database server as we expand our web site to have more...
2
by: Mark | last post by:
We have a particular software project where a minority of the function calls are taking up a majority of the cpu time. (they do a lot of geometric, trig and other functions related to vectors...
0
by: Sagaert Johan | last post by:
Hi How can i read cpu temperature, fanspeed ,etc from SMBus ? Is there a standard in reading motherboard temperature, fanspeed, etc ? Johan
34
by: Ann | last post by:
I am opening a file which looks like 0xABCDEF01 on another machine but 0x01EFCDAB on my machine. Is this a byte swapping? Could anyone give a good way to check if bytes are being swapped?...
4
by: prashant | last post by:
Guys does any body know how to develop an micro operating system using c++. or tell about how to make an executable that can interect with system hardware and does not require a ms dos to run.And...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
4
by: adeebraza | last post by:
Dear Friends, I have decided to make my project using PC’s parallel port with my hardware interface to monitor analog voltage at my VDU Screen in digital format max reading in 3 digits that is...
41
by: x01001x | last post by:
When programming in C (not C++) how does one send information to a hardware device such as a video card or modem? How is this done in Linux C programming versus Microsoft C programming?
1
by: catherine0136 | last post by:
Hello. I am pretty new to VB therefore i need guidance on the following : Basically, my circuit board is connected to solar cell and also a power supply(those laboratory DC power supply used in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.