Click here to Skip to main content
13,092,862 members (74,282 online)
Rate this:
Please Sign up or sign in to vote.
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 10-May-11 11:20am
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.
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 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...
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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 6 May 2014
Copyright © CodeProject, 1999-2017
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