Текущий архив: 2004.06.13;
Скачать: CL | DM;
ВнизПомогите извлечь флешку Найти похожие ветки
← →
Chris (2004-05-06 09:19) [0]Вроде бы нашел функцию DeviceIoControl(hDevice,FSCTL_DISMOUNT_VOLUME,nil,0,nil,0,
Но не знаю, как получить handle устройства...
← →
Игорь Шевченко © (2004-05-06 14:14) [1]
> Но не знаю, как получить handle устройства...
CreateFile ?
← →
Chris © (2004-05-07 10:53) [2]Вот в этом вся проблема - "Краткость - сестра таланта". Увы, не все люди талантливы...
Только сегодня нашел:
var c: Char;
begin
for c:="c" to "z" do
if GetDriveType(PChar(c+":\"))=DRIVE_REMOVABLE then
begin
hDev:=CreateFile(PChar("\\.\"+с+":"),0,0,nil,0,FILE_FLAG_DELETE_ON_CLOSE,nil);
Break;
end;
Вопрос с флагом... тот ли ставлю (для извлечения флешки, чтобы система не забыла очистить буфер на съемный диск)
← →
Игорь Шевченко © (2004-05-07 11:23) [3]Chris © (07.05.04 10:53)
В MSDN есть хорошая статья "How to eject removable media"
Because Windows NT uses a lazy writer system to update file system data structures on media, the media will be corrupted if the media is ejected while the system is updating this information. To avoid this problem, Win32 applications must take the following steps to correctly eject removable media and prevent possible data corruption:
Call CreateFile with GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, and OPEN_EXISTING. The lpFileName parameter should be \\.\X: (where X is the real drive letter). All other parameters can be zero.
Lock the volume by issuing the FSCTL_LOCK_VOLUME IOCTL via DeviceIoControl. If any other application or the system is using the volume, this IOCTL fails. Once this function returns successfully, the application is guaranteed that the volume is not used by anything else in the system.
Dismount the volume by issuing the FSCTL_DISMOUNT_VOLUME IOCTL. This causes the file system to remove all knowledge of the volume and to discard any internal information that it keeps regarding the volume.
Make sure the media can be removed by issuing the IOCTL_STORAGE_MEDIA_REMOVAL IOCTL. Set the PreventMediaRemoval member of the PREVENT_MEDIA_REMOVAL structure to FALSE before calling this IOCTL. This stops the device from preventing the removal of the media.
Eject the media with the IOCTL_STORAGE_EJECT_MEDIA IOCTL. If the device doesn"t allow automatic ejection, then IOCTL_STORAGE_EJECT_MEDIA can be skipped and the user can be instructed to remove the media.
Close the volume handle obtained in the first step or issue the FSCTL_UNLOCK_VOLUME IOCTL. This allows the drive to be used by other processes.
Там же код.
Адрес статьи KB165721
Удачи!
Страницы: 1 вся ветка
Текущий архив: 2004.06.13;
Скачать: CL | DM;
Память: 0.45 MB
Время: 0.024 c