|
- function GetBusType(Drive: AnsiChar): TStorageBusType;
- var
- H: THandle;
- Query: TStoragePropertyQuery;
- dwBytesReturned: DWORD;
- Buffer: array [0..1023] of Byte;
- sdd: TStorageDeviceDescriptor absolute Buffer;
- OldMode: UINT;
- begin
- Result := BusTypeUnknown;
- OldMode := SetErrorMode(SEM_FAILCRITICALERRORS);
- try
- H := CreateFile(PChar(Format('\\.\%s:', [AnsiLowerCase(Drive)])), 0, FILE_SHARE_READ or FILE_SHARE_WRITE, nil,
- OPEN_EXISTING, 0, 0);
- if H <> INVALID_HANDLE_VALUE then
- begin
- try
- dwBytesReturned := 0;
- FillChar(Query, SizeOf(Query), 0);
- FillChar(Buffer, SizeOf(Buffer), 0);
- sdd.Size := SizeOf(Buffer);
- Query.PropertyId := StorageDeviceProperty;
- Query.QueryType := PropertyStandardQuery;
- if DeviceIoControl(H, IOCTL_STORAGE_QUERY_PROPERTY, @Query, SizeOf(Query), @Buffer, SizeOf(Buffer), dwBytesReturned, nil) then
- Result := sdd.BusType;
- finally
- CloseHandle(H);
- end;
- end;
- finally
- SetErrorMode(OldMode);
- end;
- end;
复制代码
if GetBusType(driver)= BusTypeUsb then begin
if (GetDriveType(pchar(driver+':\'))=DRIVE_FIXED) then usb_hddf:=true //这是移动硬盘
else
if (GetDriveType(pchar(driver+':\'))=DRIVE_REMOVABLE then usb_flash:=true; //这是U盘
end;
[ 本帖最后由 chiannet 于 2012-12-23 09:17 编辑 ] |
|