unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm1 =
class(TForm)
mmo1: TMemo;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
const
PARTITION_BASIC_DATA_GUID = '
ebd0a0a2-b9e5-4433-87c0-68b6b72699c7';
PARTITION_ENTRY_UNUSED_GUID = '
00000000-0000-0000-0000-000000000000';
PARTITION_SYSTEM_GUID = '
c12a7328-f81f-11d2-ba4b-00a0c93ec93b';
PARTITION_MSFT_RESERVED_GUID = '
e3c9e316-0b5c-4db8-817d-f92df00215ae';
PARTITION_LDM_METADATA_GUID = '
5808c8aa-7e8f-42e0-85d2-e1e90434cfb3';
PARTITION_LDM_DATA_GUID = '
af9b60a0-1431-4f62-bc68-3311714a69ad';
PARTITION_MSFT_RECOVERY_GUID = '
de94bba4-06d1-4d40-a16a-bfd50179d6ac';
GTP_ATTRIBUTE_PLATFORM_REQUIRED = $0000000000000001;
GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER = $8000000000000000;
GPT_BASIC_DATA_ATTRIBUTE_HIDDEN = $4000000000000000;
GTP_BASIC_data_ATTRIBUTE_SHADOW_COPY = $2000000000000000;
GTP_BASIC_DATA_ATTRIBUTE_READ_ONLY = $1000000000000000;
Type
PARTITION_STYLE =
type Integer;
PARTITION_INFORMATION_MBR =
record
PartitionType: Byte;
BootIndicator: BOOL;
RecognizedPartition: BOOL;
HiddenSecorts: DWORD;
end;
PARTITION_INFORMATION_GPT =
record
PartitonType: TGUID;
PartitionId: TGUID;
Attributes: DWORD64;
Name: WCHAR;
end;
_PARTITION_INFORMATION_EX =
record
PartitionStyle: PARTITION_STYLE;
StartingOffset: LARGE_INTEGER;
PartitionLength: LARGE_INTEGER;
PartitionNumber: ULONG;
RewritePartition: Boolean;
case Integer
of
0: (Mbr: PARTITION_INFORMATION_MBR);
1: (Gpt: PARTITION_INFORMATION_GPT);
end;
const
PARTITION_STYLE_MBR = PARTITION_STYLE(0);
PARTITION_STYLE_GPT = PARTITION_STYLE(1);
PARTITION_STYLE_RAW = PARTITION_STYLE(2);
// function FindFirstVolume(lpszVolumeName: LPTSTR; cchBufferLength: DWord): THandle; stdcall; external 'kernel32.dll' name 'FindFirstVolumeW';
// function FindNextVolume(hFindVolume: THandle; lpszVolumeName: LPTSTR; cchBufferLength: DWORD): BOOL; stdcall; external 'kernel32.dll' name 'FindNextVolumeW';
// function FindVolumeClose(hFindVolume: THandle): BOOL; stdcall; external 'kernel32.dll' name 'FindVolumeClose';
// function GetVolumePathNames(lpszVolumeName: LPCTSTR; lpszVolumePathName: LPTSTR; cchBufferLength: DWORD; lpcchReturnLength: PDWORD): BOOL; stdcall; external 'kernel32.dll' name 'GetVolumePathNamesForVolumeNameW';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
h, p: Integer;
Device:
string;
hDevice: Cardinal;
PARTITION_INFORMATION_EX: _PARTITION_INFORMATION_EX;
Len: Cardinal;
StartOffset, PartLength: Int64;
begin
for h := 1
to 9
do
begin
Device:='
\\.\Harddisk1'+IntToStr(h);
hdevice:=CreateFile(PChar(Device), 0, FILE_SHARE_READ
or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, 0, 0);
if hDevice <> INVALID_HANDLE_VALUE
then
begin
DeviceIoControl(hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX,
nil, 0, @PARTITION_INFORMATION_EX, SizeOf(PARTITION_INFORMATION_EX), Len,
nil);
StartOffset:=PARTITION_INFORMATION_EX.StartingOffset.QuadPart;
PartLength:=PARTITION_INFORMATION_EX.PartitionLength.QuadPart;
mmo1.Lines.Add(Device+'
= '+IntToStr(StartOffset)+'
- '+IntToStr(PartLength));
CloseHandle(hDevice);
ZeroMemory(@PARTITION_INFORMATION_EX, 0);
end;
//end;
end;
end;
end.