dim hDevice as long
dim nDevice as long
Do
hDevice = CreateFile("\\.\PHYSICALDRIVE" & CStr(nDevice), _
0&, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
ByVal 0&, _
OPEN_EXISTING, _
0&, 0&)
If hDevice <> INVALID_HANDLE_VALUE Then
'//在这里可以添加读取硬盘数据的代码。(*)
CloseHandle hDevice
nDevice = nDevice + 1
Else
If Err.LastDllError = ERROR_FILE_NOT_FOUND Then
'No more physical drives.
Exit Do
Else
'GetPhysicalDrives error
Exit Do
End If
End If
Loop
debug.pring "硬盘总数为:" nDevice
dim Buffer(1 to 512) as Byte
dim hadRead as long
dim RetVal as long
dim i as long
RetVal = ReadFile(hDevice, Buffer(1), 512, hadRead, 0)
If RetVal And (hadRead = UBound(Buffer)) Then
for i=1 to 512
debug.print Hex$(Buffer(i)),
next
Else
'Error reading the drive.
End If