
10.05.2008, 13:07
|
Прохожий
|
|
Регистрация: 14.04.2008
Сообщения: 22
Репутация: 10
|
|
А вот такой вот код я нашел:
CD-ROM блокирует, а Флопи не хочет.
Может что-то надо поправить?
Код:
var
Form1: TForm1;
function CheckDriveType(Drive: Byte): string; //Функция Определения Типа устройств
procedure CD_Lock( DriveLetter: string; Locked: Boolean ); //Процедура блокировки-разблокировки
implementation
function CheckDriveType(Drive: Byte): string;
var
DriveLetter: Char;
DriveType: UInt;
begin
DriveLetter := Chr( Drive + $41 );
DriveType := GetDriveType( PChar( DriveLetter + ':\' ) );
case DriveType of
0 : Result := '?';
1 : Result := 'Path does not exists';
DRIVE_REMOVABLE : Result := 'Removable';
DRIVE_FIXED : Result := 'Fixed';
DRIVE_REMOTE : Result := 'Remote';
DRIVE_CDROM : Result := 'CD_ROM';
DRIVE_RAMDISK : Result := 'RAMDISK';
else
Result := 'Unknown'
end;
end;
procedure CD_Lock( DriveLetter: string; Locked: Boolean );
const
IOCTL_STORAGE_MEDIA_REMOVAL = $002D4804;
var
hDrive: THandle;
Returned: DWORD;
begin
hDrive := CreateFile( PChar( '\\.\' + DriveLetter ), GENERIC_READ,
FILE_SHARE_READ, nil, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0 );
if GetLastError <> 0 then
MessageDlg( 'Ошибка: ' + IntToStr( GetLastError ), mtError, [mbOK], 0 );
try
if not DeviceIoControl( hDrive,
IOCTL_STORAGE_MEDIA_REMOVAL, // PREVENT_MEDIA_REMOVAL,
@Locked, SizeOf( Locked ),
nil, 0, Returned, nil ) then
MessageDlg( 'Ошибка: ' + IntToStr( GetLastError ), mtError, [mbOK], 0 );
finally
CloseHandle( hDrive );
end;
end;
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
if Edit1.Text<>'' then CD_Lock( Edit1.Text, true ) else MessageDlg('Не выбрано устройство.', mtInformation, [mbOk], 0);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if Edit1.Text<>'' then CD_Lock( Edit1.Text, false ) else MessageDlg('Не выбрано устройство.', mtInformation, [mbOk], 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: 0..25;
begin
for i := 0 to 25 do
if CheckDriveType( i ) <> 'Path does not exists' then
if (CheckDriveType( i ) = 'Removable') or (CheckDriveType( i ) = 'CD_ROM') then
ComboBox1.Items.Add(Format( '%s - %s', [chr( i+$41 ), CheckDriveType( i )]));
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
Edit1.Text:=ComboBox1.Text[1]+':';
end;
end.
|