''' <param name="id">系统硬盘序号,0-255</param>
Private Shared Function Read(ByVal drive As Byte) As String
Dim driveName As String = String.Concat("\\.\PhysicalDrive", drive.ToString())
Dim device As Int32 = CreateFile( _
driveName, _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
0, _
OPEN_EXISTING, _
0, _
0)
If device = INVALID_HANDLE_VALUE Then
Return ""
End If
Dim verPara As New GETVERSIONOUTPARAMS()
Dim bytRv As Int32 = 0
If verPara.bIDEDeviceMap > 0 Then
Dim bIDCmd As Byte = CByte(IIf((verPara.bIDEDeviceMap >> drive And &H10) <> 0, IDE_ATAPI_IDENTIFY, IDE_ATA_IDENTIFY))
Dim scip As New SENDCMDINPARAMS()
Dim scop As New SENDCMDOUTPARAMS()
With scip
.cBufferSize = IDENTIFY_BUFFER_SIZE
.bDriveNumber = drive
With .irDriveRegs
.bFeaturesReg = 0
.bSectorCountReg = 1
.bCylLowReg = 0
.bCylHighReg = 0
.bDriveHeadReg = CByte((&HA0 Or ((drive And 1) << 4)))
.bCommandReg = bIDCmd
End With
End With
If DeviceIoControl(device, DFP_RECEIVE_DRIVE_DATA, scip, Marshal.SizeOf(scip), scop, Marshal.SizeOf(scop), bytRv, 0) <> 0 Then
Dim s As New StringBuilder()
Dim i As Integer
For i = 20 To 40 - 2 Step 2
s.Append(ChrW(scop.bBuffer((i + 1))))
s.Append(ChrW(scop.bBuffer(i)))
Next i