Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++
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 10-May-11 12:20pm
Hans Dietrich at 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Espen Harlinn at 20-May-11 13:13pm
Good reply :)
Sandeep Mewara at 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...
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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);

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 255
1 CHill60 240
2 Peter Leow 170
3 Richard MacCutchan 169
4 Zoltán Zörgő 150
0 Sergey Alexandrovich Kryukov 9,238
1 OriginalGriff 6,806
2 Peter Leow 4,432
3 Zoltán Zörgő 3,919
4 Richard MacCutchan 2,782

Advertise | Privacy | Mobile
Web03 | 2.8.150128.1 | Last Updated 6 May 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100