![Старый](images/statusicon/post_old.gif)
25.11.2009, 08:27
|
![Аватар для Vayrus](image.php?s=ebce0d33e423e26148708ca40f2c892b&u=4620&dateline=1258721443) |
Исполняемый Ретровирус
|
|
Регистрация: 09.08.2008
Адрес: Umbrella Corporation
Сообщения: 743
Репутация: 1293
|
|
Как определть букву USB флэшки
Привет, более или менее разобрался с определением вставки и извлечения флэшки (и тд), но возник другой вопрос, как вытащить букву диска, зная HDEVINFO, DeviceNumber, TSPDevInfoData или TSPDeviceInterfaceData ? Знаю что несложно, но запутался. Вот часть кода где необходимо определить букву диска:
Код:
procedure TForm1.UpdateDriveListBox;
var
DrivePnPHandle: HDEVINFO;
DeviceNumber:DWORD;
DevData: TSPDevInfoData;
DeviceInterfaceData: TSPDeviceInterfaceData;
RES:BOOL;
//
sSerial: String;
Buffer:array[0..4096-1] of Char;
//
S{, SymbolicName}: string;
{ I: Integer;
Inst: DEVINST;
sVendor,sVendorSpec,sProduct,sRevision: String;}
begin
DrivesListBox.Clear;
// update the list of drive mount points
// FillInRemovableDriveMountPoints(DriveMountPoints);
DrivePnPHandle := SetupDiGetClassDevs(@GUID_DEVCLASS_DISKDRIVE, nil, 0, DIGCF_PRESENT);//or DIGCF_PROFILE
if DrivePnPHandle = INVALID_HANDLE_VALUE then Exit;
DeviceNumber := 0;
repeat
// DevData:=GetMemory(sizeof(TSPDevInfoData));
DeviceInterfaceData.cbSize := SizeOf(TSPDeviceInterfaceData);
DevData.cbSize := SizeOf(TSPDevInfoData);
RES := SetupDiEnumDeviceInfo(DrivePnPHandle, DeviceNumber, DevData);
if (RES) then
begin
// if IsUSBDevice(DevData.DevInst) then//Нельзя, иначе не извлечь
CM_Get_Parent(DevData.DevInst,DevData.DevInst,0);
CM_Get_Device_ID(DevData.DevInst,Buffer,SizeOf(Buffer),0);
sSerial:=ExtractFileName(Buffer);
if Pos('&',sSerial)>0 then //sSerial:='';
sSerial := IntToStr(GetVolumeSerialNumber(S));
//Получить букву диска, а не тока описание
DrivesListBox.Items.Add(S + ' ' + GetDeviceName(DrivePnPHandle, DevData) + ' [' + sSerial + ']');
Inc(DeviceNumber);
end;
until not RES;
//
{ S := 'A:';
SymbolicName := '';
for I := 0 to DriveMountPoints.Count - 1 do
begin
S[1] := Char(DriveMountPoints.Objects[i]);
GetDriveInstanceID(DriveMountPoints[i], Inst);
// SymbolicName := GetSymbolicName(Inst);
GetInquiryData(S[1], sVendor,sVendorSpec,sProduct,sRevision);}
// DrivesListBox.Items.AddObject(S + ' [' + IntToStr(GetVolumeSerialNumber(S)) +' - '+ sVendor+sVendorSpec+sProduct+sRevision {+ ExtractSerialNumber(SymbolicName)} + ']', TObject(Inst));
{ end;}
//
SetupDiDestroyDeviceInfoList(DrivePnPHandle);
DrivesListBox.Enabled:=true;
end;
|