Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the HD vendor/serial using Windows API

Tags:

c++

c

windows

I'm talking about the physical disk drive, not volume/partition/logical drive. So that usually-suggested GetVolumeInformation function is not applicable in my case.

To be exact: I'm working directly with the disk which has not been partitioned yet. I open a handle to it via CreateFile function:

hDisk = CreateFile(
    _T("\\\\.\\PHYSICALDRIVE0"),
    GENERIC_READ|GENERIC_WRITE,
    FILE_SHARE_READ|FILE_SHARE_WRITE,
    NULL,
    OPEN_EXISTING,
    FILE_FLAG_OVERLAPPED|FILE_FLAG_NO_BUFFERING,
    NULL);

I can read/write directly on the disk using this handle. There's also a possibility to query various disk properties using DeviceIoControl function. However I couldn't find a way to query the disk vendor/serial properties, which are visible in the device manager.

like image 727
valdo Avatar asked Sep 02 '25 16:09

valdo


1 Answers

Take a look at DiskId32. Source code is there also. The idea is to use DFP_RECEIVE_DRIVE_DATA with DeviceIoControl.

like image 74
Kirill V. Lyadvinsky Avatar answered Sep 05 '25 10:09

Kirill V. Lyadvinsky