How to get the hard disk serial number correctly?

I want to get the hard disk serial number. GetVolumeInfo() can get the volume serial number, but it would changed after formating the disk. How to get the physical serial number correctly?

So use pass through and send a SCSI INQUIRY. If THAT serial number changes
you ain’t talking to the same disk.

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of disney_cheng@qq.com
Sent: Monday, June 13, 2011 8:40 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to get the hard disk serial number correctly?

I want to get the hard disk serial number. GetVolumeInfo() can get the
volume serial number, but it would changed after formating the disk. How to
get the physical serial number correctly?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

__________ Information from ESET Smart Security, version of virus signature
database 6206 (20110614) __________

The message was checked by ESET Smart Security.

http://www.eset.com

Hi,

if you want to do this in User Mode then you can either use WMI Win32_DiskDrive with Win32_PhysicalMedia or DeviceIoControl with e.g. IOCTL_CHANGER_GET_ELEMENT_STATUS, IOCTL_CHANGER_GET_PRODUCT_DATA, IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER, maybe there are some more,…

The IOCTLs are not working with all kind of drives/devices, some only work on USB devices, you have to keep that in your mind,…

best

K.