The promised code:
#RequireAdmin
#include <WinAPIFiles.au3>
#include <WinAPIHObj.au3>
MsgBox(0, 'Serial', 'Disk serial: ' & GetDiskSerial(@HomeDrive))
Func GetDiskSerial($sDriveLetter)
Local Const $IOCTL_STORAGE_QUERY_PROPERTY = 0x2D1400
Local $tagSTORAGE_PROPERTY_QUERY = 'int PropertyId; int QueryType; byte AdditionalParameters[1];'
Local $tagSTORAGE_DESCRIPTOR_HEADER = 'dword Version;dword Size;'
Local $tagSTORAGE_DEVICE_DESCRIPTOR = 'dword Version;dword Size; byte DeviceType;byte DeviceTypeModifier; boolean RemovableMedia;' & _
'boolean CommandQueueing;dword VendorIdOffset;dword ProductIdOffset;dword ProductRevisionOffset;dword SerialNumberOffset;int BusType;' & _
'dword RawPropertiesLength;byte RawDeviceProperties[1];'
Local $aDevice = _WinAPI_GetDriveNumber ($sDriveLetter)
If @error Then Return SetError(1, @error, Null)
Local $hDevice = _WinAPI_CreateFile('\\.\PhysicalDrive' & $aDevice[1], 2, 2, 6)
If @error Then Return SetError(2, @error, Null)
Local $tSTORAGE_PROPERTY_QUERY = DllStructCreate($tagSTORAGE_PROPERTY_QUERY)
$tSTORAGE_PROPERTY_QUERY.PropertyId = 0 ; StorageDeviceProperty
$tSTORAGE_PROPERTY_QUERY.QueryType = 0 ; PropertyStandardQuery
Local $tSTORAGE_DESCRIPTOR_HEADER = DllStructCreate($tagSTORAGE_DESCRIPTOR_HEADER)
If Not _WinAPI_DeviceIoControl($hDevice, $IOCTL_STORAGE_QUERY_PROPERTY, _
DllStructGetPtr($tSTORAGE_PROPERTY_QUERY), DllStructGetSize($tSTORAGE_PROPERTY_QUERY), _
DllStructGetPtr($tSTORAGE_DESCRIPTOR_HEADER), DllStructGetSize($tSTORAGE_DESCRIPTOR_HEADER)) _
Then
_WinAPI_CloseHandle($hDevice)
Return SetError(3, 0, Null)
EndIf
Local $tBuffer = DllStructCreate('byte[' & $tSTORAGE_DESCRIPTOR_HEADER.Size & ']')
If Not _WinAPI_DeviceIoControl($hDevice, $IOCTL_STORAGE_QUERY_PROPERTY, _
DllStructGetPtr($tSTORAGE_PROPERTY_QUERY), DllStructGetSize($tSTORAGE_PROPERTY_QUERY), _
DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer)) _
Then
_WinAPI_CloseHandle($hDevice)
Return SetError(4, 0, Null)
EndIf
Local $tSTORAGE_DEVICE_DESCRIPTOR = DllStructCreate($tagSTORAGE_DEVICE_DESCRIPTOR, DllStructGetPtr($tBuffer))
If $tSTORAGE_DEVICE_DESCRIPTOR.SerialNumberOffset = 0 Then
_WinAPI_CloseHandle($hDevice)
Return SetError(5, 0, Null)
EndIf
Local $tSerial = DllStructCreate('char Serial[32]', DllStructGetPtr($tBuffer) + $tSTORAGE_DEVICE_DESCRIPTOR.SerialNumberOffset)
_WinAPI_CloseHandle($hDevice)
Return $tSerial.Serial
EndFunc