Click here to Skip to main content
11,578,241 members (62,237 online)
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 11:20am
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 Richard MacCutchan 165
1 OriginalGriff 150
2 Peter Leow 150
3 Afzaal Ahmad Zeeshan 100
4 Frankie-C 75
0 OriginalGriff 880
1 Sergey Alexandrovich Kryukov 685
2 Abhinav S 573
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 393

Advertise | Privacy | Mobile
Web04 | 2.8.150603.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