Coloco de nuevo el código completo para que no aparezca el problema con la Cte
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS en los usuarios que copien el código tal cual:
Código Delphi
[-]
uses
Windows, SysUtils;
const
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS = $00560000;
function GetPhysicalDrive(Volume: Char): integer;
var
hFile: THandle;
Vde: array [0..56] of BYTE;
BytesReturned: Cardinal;
begin
Volume:= char((ord(Volume) or 32)-32);
Result:= -1;
hFile:= CreateFile(PAnsiChar('\\.\' + Volume + ':'),0,0,nil, OPEN_EXISTING, 0, 0);
if hFile <> INVALID_HANDLE_VALUE then
begin
if DeviceIoControl(hFile, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, nil, 0, @Vde, SizeOf(Vde), BytesReturned, nil) then
Result:= PBYTE(DWORD(@Vde)+8)^;
CloseHandle(hFile);
end;
end;
function GetDriveSizeFromVol(D: char): UINT64;
var
LD: DWORD;
Ch: char;
Disk: DWORD;
begin
Result:= 0;
Disk:= GetPhysicalDrive(D);
LD:= GetLogicalDrives();
Ch:= 'A';
while LD <>0 do
begin
if ((LD and $1) = 1) and (GetPhysicalDrive(Ch) = Disk) then
Inc(Result, DiskSize(Ord(Ch) - Ord('A') + 1));
LD:= LD shr 1;
inc(Ch);
end;
end;
Un ejemplo de uso:
Código Delphi
[-]
var
TotalSize: UINT64;
begin
TotalSize:= GetDriveSizeFromVol('c');
Writeln(TotalSize);
ReadLn;
end.
Saludos.