Question How to retrieve hard drive temperature?

Pescadore

Member
Joined
Nov 24, 2009
Messages
13
Programming Experience
5-10
I am looking for a way to retrieve the temperature of hard drives in VB Express 2008. I have found posts at a few different places that accomplish this with the following:

Public Function GetDriveTemp() As Integer
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")
GetDriveTemp = arrVendorSpecific(115
Next
Catch ex As ManagementException
MessageBox.Show(ex.Message)
End Try
End Function​
This function retrieves the temperature for all the hard drives in my system (excluding USB), two internal and one external esata drive. There are two problems, tough:

1. I want to know the drive letter and maybe the drive label that the retrieved temperature corresponds to. I'm assuming that the * in the query, "SELECT * FROM MSStorageDriver_ATAPISmartData", can be changed to specify a particular drive rather than all drives, but I don't know how retrieve a list of all the drives in my system or how to write the query based on those results.

2. If I call the funciton from a some click event like for a label or button, there are no problems and the return value seems valid. But when I call the function from a Timer_Tick event, the mouse cursor is the busy cursor as long as the mouse is within the form, the form doesn't receive any click events, and it cannot be closed.

I know what I'm trying to do can be done because there are a few utilities that provide this information. So, does anyone have any ideas?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,538
Location
Norway
Programming Experience
10+
With InstanceName property you can get to class Win32_DiskDrive and its PNPDeviceID. Then the path from Win32_DiskDrive to Win32_LogicalDisk is according to web search this:
Win32_DiskDrive -> Win32_DiskDriveToDiskPartition -> Win32_LogicalDiskToPartition -> Win32_LogicalDisk
So it seems to be a bit long winded. There may be "shortcuts" (perhaps DeviceID of DiskDrive can be used?) but I haven't had time to look into it, though the logical relation seems valid enough. Load up WMI Code Creator 1.0 and query the mentioned classes and you should see how these pieces of information connects.
 
Top Bottom