Click here to Skip to main content
15,860,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been hunting for c++ hard disk retrieval code for some time now, but all the ones I have seen never worked. Please who can anyone tell me where I can get a tested and trusted hard disk retrieval code.
Posted
Comments
Hans Dietrich 10-May-11 20:46pm    
I'm not sure what you mean by "trusted", but be aware that there are utilities freely available that can be used to change the HD serial number. So while you can get the current serial number, don't think it can't change.

If you just want the serial number for the logical parition, you can use this API: GetVolumeInformation.

For the serial id of the physical disk, most people use WMI. There's a CP article that shows how to do this without WMI:

Get Physical HDD Serial Number without WMI[^]

Make sure you read the comments on that article's forum - it may require admin rights on Vista/Windows 7.
 
Share this answer
 
v2
Comments
Espen Harlinn 20-May-11 13:13pm    
Good reply :)
Sandeep Mewara 25-May-12 7:14am    
Comment from some other member posted as a solution: FeedBack for Solution 1:

Hard Disk serial number differ from Volume Serial Number.. You need to do hardware level coding to retrieve that...
if you only need the serial number of the drive this will do the job. But caution: it is the number Windows gives it while the formatting process. It is NOT the number of the HD manufacturer.

DWORD serialNumber = -1;

if( ::GetVolumeInformation(lpDrive, NULL, NULL, &serialNumber, NULL, NULL, NULL, NULL ) )
{
TRACE(_T("Serial Number: %lu of drive %s\n"), serialNumber, lpDrive);
}
else
{
ASSERT(FALSE);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900