Ver Mensaje Individual
  #5  
Antiguo 14-02-2007
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Con el permiso de rruz, que tiene razón con su respuesta, aquí puedes encontrar como usar esa función:

http://www.clubdelphi.com/foros/show...99&postcount=9

O para ser mas precisos la cosa quedaría algo así:
Código Delphi [-]
type
  DISK_GEOMETRY = record
    Cylinders: int64;
    MediaType: Integer;
    TracksPerCylinder: DWORD;
    SectorsPerTrack: DWORD;
    BytesPerSector: DWORD;
  end;

const
  IOCTL_DISK_GET_DRIVE_GEOMETRY = 458752;

function GetDiskSize(Drive: Integer): int64;
var
  hDisk: THandle;
  Geometry: DISK_GEOMETRY;
  Returned: DWORD;
begin
  Result:= -1;
  hDisk:= CreateFile(PChar('\\.\Physicaldrive' + IntToStr(Drive)),GENERIC_READ,
    FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
  if hDisk <> INVALID_HANDLE_VALUE then
  begin
    FillChar(Geometry,Sizeof(Geometry),0);
    if DeviceIoControl(hDisk,IOCTL_DISK_GET_DRIVE_GEOMETRY,nil,0,@Geometry,
      sizeof(Geometry),Returned,nil) then
      with Geometry do
        Result:= Cylinders*TracksPerCylinder*SectorsPerTrack*BytesPerSector;
    CloseHandle(hDisk);
  end;
end;


// Por ejemplo
ShowMessage(IntToStr(GetDiskSize(0)));

O si queremos un listado completo:
Código Delphi [-]
var
  i: integer;
  Str: String;
  Size: int64;
begin
  Str:= '';
  for i:= 0 to 16 do  // Comprobamos un numero razonable de discos
  begin
    Size:= GetDiskSize(i);
    if Size > 0 then
      Str:= Format('Disco %d = %d Bytes' + #13#10,[i,Size]);
  end;
  ShowMessage(Str);
end;
Responder Con Cita