Retrieving Hard Drive Temperature (S.M.A.R.T)
-
Sunday, January 22, 2006 3:39 AM
Hi,
Does anyone know how to retrieve the temperature of a hard drive in Visual Basic 2005? The temperature can be retrieved from the S.M.A.R.T information, but I don't know how to do that in Visual Basic 2005. There probably is a way, but unfortunately, I don't know.
If anyone could help me with this, it would be great!
--daniel15
http://www.dansoftaustralia.net/ - DanSoft Australia
http://www.frihost.com/ - Free Reliable Internet Hosting
Answers
-
Monday, January 23, 2006 2:20 AM
Hi Daniel15,
I'm afraid I'm not too familiar with how those implementations work. Just a couple of things I'm throwing out there - can you ensure that the drive has SMART enabled. IIRC, you can disable/enable it from the BIOS (and probably from Software as well). Looks like its looking for some driver file or something..can you check if that's the case?
Sorry..can't be of much help. good luck.
Imran. -
Monday, January 23, 2006 10:48 AM
Daniel,
try this:
http://vbnet.mvps.org/index.html?code/disk/smartide.htm
or google for: smart ioctl api
Might help, is the info you require exposed in WMI ?.
Rob.
-
Monday, January 23, 2006 4:49 PM
hi daniel,
using WMI calls we can able to retrieve the hard drive temperature. Download this WMI code creator tool from this URL..
http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e&DisplayLang=en
this tool automatically creates vb.net c#.net and vbscript codes..
i think this will help u.
i posted one thread today. if u know the answer for that then reply.
thx.
kamaraj -
Monday, April 11, 2011 4:38 PMModerator
I put together a blog post and code that solves the "why is it 115" mystery and has the proper data structures.
- Marked As Answer by Clemens Vasters - MSFTModerator Monday, April 11, 2011 4:38 PM
All Replies
-
Sunday, January 22, 2006 6:07 AMYou might want to take a look at some of the existing implementations that you might find here: http://smartlinux.sourceforge.net/smart/index.php
There's one in VC++ that might be helpful. Trying to accomplish that from scratch might be a tall order especially if all you want is the temperature and no other information.
hope that helps,
Imran. -
Sunday, January 22, 2006 8:27 AM
Hi,
Thanks for your reply. Unfortunately, I couldn't get the C++ demo working (I used the binary that came in the rar file). I got this error:
Unable to open SMARTVSD, error code: 0x2
Also, I'm not really sure how I'd implement that in a Visual Basic 2005 program (I don't know anything about C++)
--daniel15
-
Monday, January 23, 2006 2:20 AM
Hi Daniel15,
I'm afraid I'm not too familiar with how those implementations work. Just a couple of things I'm throwing out there - can you ensure that the drive has SMART enabled. IIRC, you can disable/enable it from the BIOS (and probably from Software as well). Looks like its looking for some driver file or something..can you check if that's the case?
Sorry..can't be of much help. good luck.
Imran. -
Monday, January 23, 2006 10:48 AM
Daniel,
try this:
http://vbnet.mvps.org/index.html?code/disk/smartide.htm
or google for: smart ioctl api
Might help, is the info you require exposed in WMI ?.
Rob.
-
Monday, January 23, 2006 12:39 PM-- is the info you require exposed in WMI ?
nope - CurrentReading property of Win32_TemperatureProbe is not populated.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_temperatureprobe.asp
Imran. -
Monday, January 23, 2006 4:49 PM
hi daniel,
using WMI calls we can able to retrieve the hard drive temperature. Download this WMI code creator tool from this URL..
http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e&DisplayLang=en
this tool automatically creates vb.net c#.net and vbscript codes..
i think this will help u.
i posted one thread today. if u know the answer for that then reply.
thx.
kamaraj -
Tuesday, January 24, 2006 3:25 AM
Hi Daniel15,
I'm afraid I'm not too familiar with how those implementations work. Just a couple of things I'm throwing out there - can you ensure that the drive has SMART enabled. IIRC, you can disable/enable it from the BIOS (and probably from Software as well). Looks like its looking for some driver file or something..can you check if that's the case?
Sorry..can't be of much help. good luck.
Imran.Hi,
Yes, SMART is enabled for the drive (A Western Digital 120GB drive). Programs like HDDlife can successfully get the hard drive SMART information, including the temperature.
@Rob1010: Thanks, I'll try that in a few days, unfortunately I'm pretty busy at the moment
@itKamaraj: According to Imran Koradia, the temperature information isn't available through WMI, so it won't help. I might try it anyway however (it's always better to try something :D)
I'll be sure to tell you if I get it working
--daniel15
-
Tuesday, January 24, 2006 3:39 AMdaniel15,
Good luck. Let us know how it goes. It'll be good to know and will probably help someone in future as well.
Imran. -
Thursday, January 26, 2006 7:02 AM
Well, I figured it out. The temperature is actually hiding in the Vendor Specific array, in the MSStorageDriver_ATAPISmartData class. Thanks for suggesting to use WMI! I'll put the code I used below.
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)
Imports
SystemImports
System.ManagementImports
System.Windows.FormsPublic
Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim searcher As New ManagementObjectSearcher( _ "root\WMI", _ "SELECT * FROM MSStorageDriver_ATAPISmartData") For Each queryObj As ManagementObject In searcher.Get() Dim arrVendorSpecific As Byte() = queryObj("VendorSpecific")MsgBox(
"Temperature = " & arrVendorSpecific(115)) Next Catch err As ManagementExceptionMessageBox.Show(
"An error occurred while querying for WMI data: " & err.Message) End Try End SubEnd
Class -
Thursday, January 26, 2006 4:14 PMhey Daniel15,
Good stuff !! Glad that worked out for you and in the process I learnt something new as well :)
Thanks for sharing that.
Imran. -
Wednesday, March 07, 2007 8:59 PM
hi, i'd just have a look on the smartlinux.sourceforge project, and get the same error as you, (Unable to open SMARTVSD, error code: 0x2) This is because the program "think" you are under Windows 98 . In smartapp.c (OpenSmart(..) fct ) we can see :
HANDLE OpenSMART(VOID)
{
HANDLE hSMARTIOCTL = 0;#ifdef WINDOWS9X
// Version Windows 95 OSR2, Windows 98
if ((hSMARTIOCTL = CreateFile("\\\\.\\SMARTVSD", 0,0,0,
CREATE_NEW, 0, 0)) == INVALID_HANDLE_VALUE)
{
printf("Unable to open SMARTVSD, error code: 0x%lX\n", GetLastError());
}
else
{
printf("SMARTVSD opened successfully\n");
}
#else
// Windows NT, Windows 2000*/
if ((hSMARTIOCTL = CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,
OPEN_EXISTING,0,NULL)) == INVALID_HANDLE_VALUE)
{
printf("Unable to open physical drive, error code: 0x%lX\n", GetLastError());
}
else
{
printf("Physical drive opened successfully\n");
}
#endif
return hSMARTIOCTL;}
And i think you work with Windows XP, so if you modify the file like this :
HANDLE OpenSMART(VOID)
{
HANDLE hSMARTIOCTL = 0;if ((hSMARTIOCTL = CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,
OPEN_EXISTING,0,NULL)) == INVALID_HANDLE_VALUE)
{
printf("Unable to open physical drive, error code: 0x%lX\n", GetLastError());
}
else
{
printf("Physical drive opened successfully\n");
}
return hSMARTIOCTL;}
I'm sure it will work. So if the application need to be run on different systems, you have to modify "#ifdef WINDOWS9X" with the correct one.
sorry for my poor english ;)
-
Wednesday, November 07, 2007 8:49 PM
Thanks for posting this. I realize it has been a while since this thread was created, but...
What if you have more than one hard drive and would llike to display the temp and name or model number of the specific hard drive? I can get a temp from the code here and I found something similar to get hard drive names/model/serial number, but I can't figure out how to get it all together! Thanks for any help.
Tony - Memphis
-
Wednesday, January 23, 2008 6:59 AM
Hello,
I am unable to fetch the values using this code. It is raising the exception saying "Not Supported". I had tried to use WMICreator utility also and tried to use root/CIMV2 and root/WMI they had those properties with them but they aren't giving any values.
I would be very thankful to you if you could help me related to this.
Waiting for a reply from your side as soon as possible.
Thanks in advance. -
Tuesday, March 04, 2008 12:43 PMHi All
How to get all the smart information of hard disk using vb.net or c#.net
It is very urgent please
Thank in advance -
Tuesday, October 14, 2008 8:34 PMHi Daniel15,
I have a question about your code to access WMI... how do you know that temperature value is stored in arrVendorSpecific(115)? How is this indexed? Can you please help? Thanks.
Bill -
Wednesday, April 15, 2009 9:34 AMHallo,
i know this thread is old but i have the same Question as billgaitas.
how do you know that temperature value is stored in arrVendorSpecific(115)?
What ist the answer of this question?
It is possible to work with C#, VB or anything else, and use 'S.M.A.R.T Read Values'?
I have seen that in a C++ Application.
Sorry for my bad english..
Waiting for a reply from your side as soon as possible.
Yours sincerely,
kai -
Thursday, January 27, 2011 8:21 PM
This is how I did it. The temperature value is not stored in arrVendorSpecific(115) for all Hard Disk Models.
http://daran9.wordpress.com/2011/01/24/howto-get-harddisk-temperature-with-net/
-
Monday, April 11, 2011 4:38 PMModerator
I put together a blog post and code that solves the "why is it 115" mystery and has the proper data structures.
- Marked As Answer by Clemens Vasters - MSFTModerator Monday, April 11, 2011 4:38 PM
-
Monday, April 25, 2011 11:11 PM
Clemens,
thank you for the code. It works.
Here's my output:
----------------------------------- MSStorageDriver_ATAPISmartData instance ----------------------------------- ReadErrorRate :200 : 1 0 0 0 0 0 0 0 SpinUpTime :181 : 6c 7 0 0 0 0 0 0 StartStopCount :100 : 28 0 0 0 0 0 0 0 ReallocatedSectorsCount :200 : 0 0 0 0 0 0 0 0 SeekErrorRate :200 : 0 0 0 0 0 0 0 0 PowerOnHoursPOH :100 : 5b 1 0 0 0 0 0 0 SpinRetryCount :253 : 0 0 0 0 0 0 0 0 CalibrationRetryCount :253 : 0 0 0 0 0 0 0 0 PowerCycleCount :100 : 28 0 0 0 0 0 0 0 PoweroffRetractCount :200 : 4 0 0 0 0 0 0 0 LoadCycleCount :200 : 28 0 0 0 0 0 0 0 Temperature :109 : 1f 0 0 0 0 0 0 0 ReallocationEventCount :200 : 0 0 0 0 0 0 0 0 CurrentPendingSectorCount :200 : 0 0 0 0 0 0 0 0 UncorrectableSectorCount :253 : 0 0 0 0 0 0 0 0 MultiZoneErrorRate :253 : 0 0 0 0 0 0 0 0
Do i see it right? My HD temperature is 109? Is it in Fahrenheit or Celsius? I'm running Win XP 64 bit with Solid State Hard Drive at 10000RPM.I have Outlook, 2xVisual Studio 2008, two folders, Command Prompt, Notpad, Chrome with 5 tabs. My other concern and question are, will this work with a PC with multiple drives? I need to test it out when I get home. I have a PC at home with 6 drives. 1=OS and 5=Raid5 for data storage. I want to write a windows service to monitor the temperature of the HDs to make sure they don't burn alive in the PC Case. The Case temp is around 30C. But who knows what it will be when I put it in the storage and out of my view.
I want my windows service to notify me when something goes wrong.Thanks again.
-
Monday, April 25, 2011 11:57 PM
Okay, here's a thread that expand a little further:
-
Saturday, July 30, 2011 2:02 PM
Almost, I never use WMI for several reasons. Using WMI inslow and a poor performer. Also WMI is an "easy" way to get the information. Wmi uses database techniques.
Renee

