//procedure TMainForm.CD_Lock(Locked: Boolean, DriveLetter: string); const IOCTL_STORAGE_MEDIA_REMOVAL = $002D4804; var hDrive: THandle; Returned: DWORD; DisableEject: boolean; begin hDrive := CreateFile(PChar('\\.\' + 'E:'), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if GetLastError <> 0 then MessageDlg('Error:' + IntToStr(GetLastError), mtError, [mbOK], 0); try DisableEject := false; if not DeviceIoControl(hDrive, IOCTL_STORAGE_MEDIA_REMOVAL, // PREVENT_MEDIA_REMOVAL, @DisableEject, SizeOf(DisableEject), nil, 0, Returned, nil) then MessageDlg('Îøèáêà:' + IntToStr(GetLastError), mtError, [mbOK], 0) finally CloseHandle(hDrive) end;