Mega Code Archive

 
Categories / Delphi / Examples
 

Check if a disk is ready

function IsDriveReady(Root: string): Boolean; var Oem: Cardinal; Dw1, Dw2: DWORD; begin Oem := SetErrorMode(SEM_FAILCRITICALERRORS); if Length(Root) = 1 then Root := Root + ':\'; Result := GetVolumeInformation(PChar(Root), nil, 0, nil, Dw1, Dw2, nil, 0); SetErrorMode(Oem); end; procedure TForm1.Button1Click(Sender: TObject); begin if IsDriveReady('A') = True then ShowMessage('Drive ready !') else ShowMessage('Drive not ready !'); end;