Prüfen ob ein Laufwerk bereit ist, Typ bestimmen, Fehlermeldungen unterdrücken(Tipp drucken)



function IsDriveReady(DriveLetter: char): Boolean;
var
  RetValue: Word;
  Dir: string;
begin
  // displays no error-dialog id drive is not ready, i.e. 'A:\'
  RetValue := SetErrorMode(SEM_NOOPENFILEERRORBOX + SEM_FAILCRITICALERRORS);
  GetDir (0, Dir);
  {$I-}
    ChDir (DriveLetter + ':\');
  {$I+}
  if IoResult <> 0 then
    Result := false
  else
    Result := true;

  ChDir (Dir);
  SetErrorMode(RetValue);
end;

function GetDriveTyp (DriveLetter: char): string;
begin
  case GetDriveType(PChar(DriveLetter + ':\')) of
    0                : Result := 'Not Available';
    1                : Result := 'Drive has no Root Directory';
    DRIVE_REMOVABLE  : Result := 'Drive is RemoveAble';
    DRIVE_FIXED      : Result := 'Drive cannot be Removed';
    DRIVE_REMOTE     : Result := 'Drive Is on NetWork';
    DRIVE_CDROM      : Result := 'Drive Is CDRom';
    DRIVE_RAMDISK    : Result := 'Drive Is RamDisk';
  end;
end;

function TestDrives: string;
begin
  if IsDriveReady ('A') then
    Result := 'Drive Is Ready'
  else
    Result := 'Drive Is not Ready';
  Result := Result + #10#13 + GetDriveTyp ('A');
end;