Click here to Skip to main content
15,887,812 members
Articles / Programming Languages / C++
Article

Hard drive information using S.M.A.R.T.

Rate me:
Please Sign up or sign in to vote.
4.33/5 (31 votes)
25 May 2007 341.4K   18K   70   100
Retrieving Hard drive information using S.M.A.R.T.

Sample Image - SMARTIMAGE.jpg

Introduction

This is very simple program which communicates with the Hard drive to get the information using S.M.A.R.T. available within the hard drive.

The core part is to prepare the command structure and pass it to the device driver which communicates with the hard drive. It uses the DeviceIoControl function. For eg: bRet=DeviceIoControl(hDevice,SMART_SEND_DRIVE_COMMAND,&stCIP,sizeof(stCIP),&stCOP,sizeof(stCOP),&dwRet,NULL);

Don't forget to include the "DDKInclude" folder in the workspace to your VC's include folder before compiling. This sample is only intended for beginners. Most of the information for S.M.A.R.T. is available in the net.

Also the information for each id is stored in an .ini file. You can see that in the Debug / Release folder.

Double click on any of the item in the list box to get more information about it. For e.g., xx sector count

Please contact me for any doubts and i will be happy to answer to your questions

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
I am from the beautiful sea side town called Kochi ( cochin), Kerala, South India.

Comments and Discussions

 
AnswerRe: Admin rights required? Pin
Saneesh26-Sep-07 11:15
Saneesh26-Sep-07 11:15 
GeneralCannot Detect any information under Vista OS Pin
mywork_00710-Aug-07 20:59
mywork_00710-Aug-07 20:59 
GeneralRe: Cannot Detect any information under Vista OS Pin
Saneesh12-Aug-07 13:12
Saneesh12-Aug-07 13:12 
GeneralRe: Cannot Detect any information under Vista OS Pin
mywork_00712-Aug-07 21:16
mywork_00712-Aug-07 21:16 
GeneralRe: Cannot Detect any information under Vista OS Pin
Saneesh13-Aug-07 4:03
Saneesh13-Aug-07 4:03 
GeneralRe: Cannot Detect any information under Vista OS Pin
mywork_00713-Aug-07 21:40
mywork_00713-Aug-07 21:40 
GeneralRe: Cannot Detect any information under Vista OS Pin
Jonas Nordlund7-Nov-07 12:20
Jonas Nordlund7-Nov-07 12:20 
GeneralProblem with hard drive enumeration Pin
Nathan Lewis15-Jun-07 6:57
Nathan Lewis15-Jun-07 6:57 
There is a problem with the way you are enumerating the fixed drives in ReadSMARTValuesForAllDrives(). Let me explain...

First, keep in mind that the first fixed drive is at index 0, the second at index 1, the third at index 2, and so on. They will always be in sequence, not in some semi-random order such as "1, 3, 4, 8...".

Also, there is not necessarily a one-to-one correlation between the drive letters and the hard drives physically present in the system. For example, the drive at physical index 0 may contain two logical drives (partitions) mounted as drive letters "C:" and "D:", so referencing them as physical drives 0 and 1 will not work correctly.

As a further example, consider my own system: I have two physical drives installed in the machine, with a single partition on each, mounted as drive letters "C:" and "G:". So, looking at your code:
<br />
   case DRIVE_FIXED:<br />
      ucDriveIndex=ucT2-2;<br />
      if(ReadSMARTInfo(ucDriveIndex))<br />
         m_ucDrivesWithInfo++;<br />
      m_ucDrives++;<br />
   break;<br />

As you can see, it will attempt to load data for drive 0 ( ucT2 == 2, ucDriveIndex == 0 ) and drive 4 ( ucT2 == 6, ucDriveIndex == 4 ). And since the system only recognizes physical hard drives 0 and 1, this code will fail to display information for the second drive.

The solution is to not enumerate the list of logical drives, but the actual physical drives instead, e.g.:
<br />
   BOOL CSmartReader::ReadSMARTValuesForAllDrives()<br />
   {<br />
      static const BYTE MAX_DRIVES = 32;<br />
<br />
      for( BYTE ucIndex = 0; ucIndex < MAX_DRIVES; ucIndex++ )<br />
      {<br />
         if( ReadSMARTInfo( ucIndex ) )<br />
            m_ucDrivesWithInfo++;<br />
      }<br />
<br />
      return TRUE;<br />
   }<br />

Of course, this breaks m_ucDrives completely, but you could easily update it inside the ReadSMARTInfo() function instead, e.g.:
<br />
   BOOL CSmartReader::ReadSMARTInfo(BYTE ucDriveIndex)<br />
   {<br />
      ...code...<br />
<br />
      if(hDevice!=INVALID_HANDLE_VALUE)<br />
      {<br />
         // Found a valid drive, which may or may not support SMART<br />
         m_ucDrives++;<br />
<br />
      ...more code...<br />
   }<br />



Hope this helps!

- NL


*Real* programmers use "copy con:progname.exe"!

GeneralRe: Problem with hard drive enumeration Pin
Saneesh15-Jun-07 9:27
Saneesh15-Jun-07 9:27 
Generalinvalid informarion with SATA II drives on Vista Pin
Mario M.26-May-07 12:34
Mario M.26-May-07 12:34 
GeneralRe: invalid informarion with SATA II drives on Vista Pin
Saneesh27-May-07 6:44
Saneesh27-May-07 6:44 
GeneralRe: invalid informarion with SATA II drives on Vista Pin
mywork_00710-Aug-07 20:54
mywork_00710-Aug-07 20:54 
GeneralRe: invalid informarion with SATA II drives on Vista Pin
Saneesh12-Aug-07 13:11
Saneesh12-Aug-07 13:11 
QuestionStorage Arrays and SANS Pin
sides_dale25-May-07 18:20
sides_dale25-May-07 18:20 
AnswerRe: Storage Arrays and SANS Pin
Saneesh5-Jun-07 6:40
Saneesh5-Jun-07 6:40 
GeneralZip is Corrupt Pin
girish_ksharma22-May-07 21:09
girish_ksharma22-May-07 21:09 
QuestionRe: Zip is Corrupt Pin
Saneesh23-May-07 4:33
Saneesh23-May-07 4:33 
GeneralThreshold values always are zero Pin
GipsySh26-Apr-07 22:09
GipsySh26-Apr-07 22:09 
GeneralRe: Threshold values always are zero Pin
Saneesh27-Apr-07 4:30
Saneesh27-Apr-07 4:30 
GeneralRe: Threshold values always are zero Pin
GipsySh27-Apr-07 11:56
GipsySh27-Apr-07 11:56 
GeneralRe: Threshold values always are zero Pin
Saneesh28-Apr-07 19:25
Saneesh28-Apr-07 19:25 
GeneralRe: Threshold values always are zero Pin
GipsySh21-May-07 4:11
GipsySh21-May-07 4:11 
GeneralRe: Threshold values always are zero Pin
Nathan Lewis15-Jun-07 7:44
Nathan Lewis15-Jun-07 7:44 
QuestionHow about 2 HDD's using RAID? Pin
Ingenious00127-Mar-07 5:30
Ingenious00127-Mar-07 5:30 
AnswerRe: How about 2 HDD's using RAID? Pin
Saneesh27-Mar-07 12:26
Saneesh27-Mar-07 12:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.