I have a working code for both:
const
// Max number of drives assuming primary/secondary, master/slave topology
MAX_IDE_DRIVES = 16;
var
i: Integer;
DiskType: Byte;
RawMBR: array[0..511] of Byte;
btsIO: DWORD;
hDevice: THandle;
s: string;
begin
s := '';
for i := 0 to MAX_IDE_DRIVES - 1 do
begin
hDevice := CreateFile(PChar('\\.\PHYSICALDRIVE' + IntToStr(i)), GENERIC_READ,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice <> INVALID_HANDLE_VALUE then
begin
SetFilePointer(hDevice, 512, nil, FILE_BEGIN); //sector 1 for GPT
ReadFile(hDevice, RawMBR[0], 512, btsIO, nil);
if (IntToHex(RawMBR[0], 2) + IntToHex(RawMBR[1], 2) +
IntToHex(RawMBR[2], 2) + IntToHex(RawMBR[3], 2) +
IntToHex(RawMBR[4], 2) + IntToHex(RawMBR[5], 2) +
IntToHex(RawMBR[6], 2) + IntToHex(RawMBR[7], 2)) =
'4546492050415254' then //EFI PART
DiskType := 1 //GPT
else
begin
DiskType := 0; //MBR
SetFilePointer(hDevice, 0, nil, FILE_BEGIN); //sector 0 for MBR
ReadFile(hDevice, RawMBR[0], 512, btsIO, nil);
end;
CloseHandle(hDevice);
if DiskType = 0 then
s := s + 'Disk ' + IntToStr(i) + ' = ' + IntToHex(RawMBR[443], 2) + ' ' +
IntToHex(RawMBR[442], 2) + ' ' + IntToHex(RawMBR[441], 2) +
' ' + IntToHex(RawMBR[440], 2) + #13#10
else
s := s + 'Disk ' + IntToStr(i) + ' = ' + IntToHex(RawMBR[59], 2) +
' ' + IntToHex(RawMBR[58], 2) + ' ' + IntToHex(RawMBR[57], 2) +
' ' + IntToHex(RawMBR[56], 2) + ' - ' + IntToHex(RawMBR[61], 2) +
' ' + IntToHex(RawMBR[60], 2) + ' - ' + IntToHex(RawMBR[63], 2) +
' ' + IntToHex(RawMBR[62], 2) + ' - ' + IntToHex(RawMBR[64], 2) +
' ' + IntToHex(RawMBR[65], 2) + ' - ' + IntToHex(RawMBR[66], 2) +
' ' + IntToHex(RawMBR[67], 2) + ' ' + IntToHex(RawMBR[68], 2) +
' ' + IntToHex(RawMBR[69], 2) + ' ' + IntToHex(RawMBR[70], 2) +
' ' + IntToHex(RawMBR[71], 2) +
#13#10;
end;
end;
ShowMessage(s);
end;
Ok, now to implement this in the rest of the code