Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   API de Windows (https://www.clubdelphi.com/foros/forumdisplay.php?f=7)
-   -   CD-ROM o CD-RW o DVD .... (https://www.clubdelphi.com/foros/showthread.php?t=39082)

Roilo 10-01-2007 00:22:32

CD-ROM o CD-RW o DVD ....
 
Saludos al FORO.
FELICIDADES por este nuevo año.
Me preguntaba si conocen alguna forma de determinar si la torre de CD instalada en un equipo es RW o DVD o simplemente CD-R...
GRACIAS.

Neftali [Germán.Estévez] 10-01-2007 11:12:07

¿Has revisado componentes de información sobre el hardware de la máquina?
Estoy seguro que no deben tener problemas para saber el tipo de la unidad.

seoane 10-01-2007 13:44:50

Este ejemplo esta basado en este otro de microsoft:

http://support.microsoft.com/kb/305184

Código Delphi [-]
const
  SPT_SENSE_LENGTH = 32;
  SPTWB_DATA_LENGTH = 512;

  CDB6GENERIC_LENGTH = 6;
  SCSI_IOCTL_DATA_IN = 1;
  SCSIOP_INQUIRY = $12;
  SCSIOP_MODE_SENSE = $1A;
  MODE_PAGE_CAPABILITIES = $2A;
  IOCTL_SCSI_PASS_THROUGH = $04D004;

type
  ULONG_PTR = ULONG;

  SCSI_PASS_THROUGH = record
    Length: Word;
    ScsiStatus: UCHAR;
    PathId: UCHAR;
    TargetId: UCHAR;
    Lun: UCHAR;
    CdbLength: UCHAR;
    SenseInfoLength: UCHAR;
    DataIn: UCHAR;
    DataTransferLength: ULONG;
    TimeOutValue: ULONG;
    DataBufferOffset: ULONG_PTR;
    SenseInfoOffset: ULONG;
    Cdb: array[0..15] of UCHAR;
  end;
  PSCSI_PASS_THROUGH = ^SCSI_PASS_THROUGH;

  SCSI_PASS_THROUGH_WITH_BUFFERS = record
    spt: SCSI_PASS_THROUGH;
    Filler: ULONG;
    ucSenseBuf: array[0..SPT_SENSE_LENGTH-1] of UCHAR;
    ucDataBuf: array[0..SPTWB_DATA_LENGTH-1]of UCHAR;
  end;
  PSCSI_PASS_THROUGH_WITH_BUFFERS = ^SCSI_PASS_THROUGH_WITH_BUFFERS;

function offsetof(a,b: Pointer): integer;
begin
  Result:= Integer(b) - Integer(a);
end;

function BoolToSiNo(Value: Boolean): String;
begin
  if Value then
    Result:= 'Si'
  else
    Result:= 'No';
end;

function GetDeviceProperty(Letra: Char): string;
var
  Disk: THandle;
  Sptwb: SCSI_PASS_THROUGH_WITH_BUFFERS;
  l: ULONG;
  Returned: Cardinal;
begin
  Result:= EmptyStr;
  Disk:= CreateFile(PChar('\\.\' + Letra + ':'),GENERIC_READ or GENERIC_WRITE,
    FILE_SHARE_READ or FILE_SHARE_WRITE,nil,OPEN_EXISTING,0,0);
    
  if Disk <> INVALID_HANDLE_VALUE then
  begin
    FillChar(Sptwb,Sizeof(Sptwb),0);
    Sptwb.Spt.Length:= sizeof(SCSI_PASS_THROUGH);
    Sptwb.Spt.PathId:= 0;
    Sptwb.Spt.TargetId:= 1;
    Sptwb.Spt.Lun:= 0;
    Sptwb.Spt.CdbLength:= CDB6GENERIC_LENGTH;
    Sptwb.Spt.SenseInfoLength:= 24;
    Sptwb.Spt.DataIn:= SCSI_IOCTL_DATA_IN;
    Sptwb.Spt.DataTransferLength:= 192;
    Sptwb.Spt.TimeOutValue:= 2;
    Sptwb.Spt.DataBufferOffset:=
       offsetof(@Sptwb,@Sptwb.ucDataBuf);
    Sptwb.Spt.SenseInfoOffset:=
       offsetof(@Sptwb,@Sptwb.ucSenseBuf);
    Sptwb.Spt.Cdb[0]:= SCSIOP_MODE_SENSE;
    Sptwb.Spt.Cdb[1]:= $08;
    Sptwb.Spt.Cdb[2]:= MODE_PAGE_CAPABILITIES;
    Sptwb.Spt.Cdb[4]:= 192;

    l:= offsetof(@Sptwb,@Sptwb.ucDataBuf) +
       sptwb.Spt.DataTransferLength;

    if DeviceIoControl(Disk,IOCTL_SCSI_PASS_THROUGH,@Sptwb,
      Sizeof(SCSI_PASS_THROUGH),@sptwb,l,Returned,nil) then
    begin
       if ((Sptwb.ucDataBuf[6] and $01) or (Sptwb.ucDataBuf[6] and $02) > 0) then
       begin
         Result:= 'CD Reader: Si';
         Result:= Result + #13#10 + 'CD-R: ' + BoolToSiNo((Sptwb.ucDataBuf[6] and $01)>0);
         Result:= Result + #13#10 + 'CD-RW: ' + BoolToSiNo((Sptwb.ucDataBuf[6] and $02)>0);
         if (Sptwb.ucDataBuf[7] and $01) or (Sptwb.ucDataBuf[7] and $02) > 0 then
         begin
           Result:= Result + #13#10#13#10 + 'CD Writer: Si';
           Result:= Result + #13#10 + 'CD-R: ' + BoolToSiNo((Sptwb.ucDataBuf[7] and $01)>0);
           Result:= Result + #13#10 + 'CD-RW: ' + BoolToSiNo((Sptwb.ucDataBuf[7] and $02)>0);
         end else Result:= Result + #13#10#13#10 + 'CD Writer: No';
       end else Result:= 'CD Reader: No';

       if (Sptwb.ucDataBuf[6] and $08) or (Sptwb.ucDataBuf[6] and $10) or
         (Sptwb.ucDataBuf[6] and $20) > 0 then
       begin
         Result:= Result + #13#10#13#10 + 'DVD Reader: Si';
         Result:= Result + #13#10 + 'DVD-ROM: ' + BoolToSiNo((Sptwb.ucDataBuf[6] and $08)>0);
         Result:= Result + #13#10 + 'DVD-R: ' + BoolToSiNo((Sptwb.ucDataBuf[6] and $10)>0);
         Result:= Result + #13#10 + 'DVD-RAM: ' + BoolToSiNo((Sptwb.ucDataBuf[6] and $20)>0);
         if ((Sptwb.ucDataBuf[7] and $10) or (Sptwb.ucDataBuf[7] and $20) > 0) then
         begin
           Result:= Result + #13#10#13#10 + 'DVD Writer: Si';
           Result:= Result + #13#10 + 'DVD-R: ' + BoolToSiNo((Sptwb.ucDataBuf[7] and $10)>0);
           Result:= Result + #13#10 + 'DVD-RAM: ' + BoolToSiNo((Sptwb.ucDataBuf[7] and $20)>0);
         end else Result:= Result + #13#10#13#10 + 'DVD Writer: No';
       end else Result:= Result + #13#10#13#10 + 'DVD Reader: No';
    end else Result:= SysErrormessage(GetLastError);
    CloseHandle(Disk);
  end else Result:= SysErrormessage(GetLastError);
end;

// Por ejemplo
ShowMessage(GetDeviceProperty('d'));

Roilo 10-01-2007 16:22:37

Gracias
 
Me gusta ese inicio, pero ahora tengo otra.
ese parámetro que le damos a la función GetDeviceProperty, que se trata nada más y nada menos que de la unidad de disco, está fijo, y no en todas las máquinas la torre de discos está en 'd'. Yo encontré una función que me devuelve la letra de la unidad del disco, pero me la devuelve de tipo string y el parámetro que le pasamos a la funcióm GetDeviceProperty es de tipo char. Me pregunto si conoces algun STRTOCHAR o algo parecido...:confused:
GRACIAS.

dec 10-01-2007 16:30:30

Hola,

Código Delphi [-]
var
  s: string;
begin
  {...}
  GetDeviceProperty( PChar(s) );
end;

seoane 10-01-2007 16:51:31

Cita:

Empezado por dec
GetDeviceProperty( PChar(s) );


:D Jeje, muy ingenioso dec aunque yo añadiria
Código Delphi [-]
  GetDeviceProperty( PChar(s)^ );

Otra forma de hacerlo:
Código Delphi [-]
  if Length(s) > 0 then
    GetDeviceProperty( s[1] );

y la que yo usaria:
Código Delphi [-]
var
  Letra: Char;
begin
  for Letra:= 'A' to 'Z' do
    if GetDriveType(Pchar(Letra+':\')) = DRIVE_CDROM  then
    begin
       ShowMessage(GetDeviceProperty(Letra));
    end;
end;

Roilo 10-01-2007 17:21:21

Ideal...
 
Les agradesco de nuevo, todo ha salido como agua.
Neftali, cuáles componentes son esos que te brinda información sobre la máquina y donde los puedo encontrar.
GRACIAS.

Neftali [Germán.Estévez] 10-01-2007 18:35:53

Cita:

Empezado por Roilo
Neftali, cuáles componentes son esos que te brinda información sobre la máquina y donde los puedo encontrar.

Aquí puedes encontrar unos cuantos, y si buscas por internet te aparecerán muchos más...
Personalmente he revisado el de MiTEC y es muy bueno; No se cómo se distribuye ahora, pero en versiones antiguas era gratuíto.

Roilo 11-01-2007 22:13:51

Gracias...
 
Muy valiosos sus aportes...
Hasta Luego.


La franja horaria es GMT +2. Ahora son las 00:23:30.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi