2010-07-01 60 views

回答

0

您可以使用GetDriveType獲得基本的接口類型(如:可移動設備,CDROM,RAMDisk中)驅動器號,也看到了最後的評論在該頁面的底部可移動設備上多一點信息。還檢查了SetupDiGetDeviceRegistryPropertyDeviceIoControl

她是我能拿出最好的例子(未經測試,因爲我沒有WDK/DDK)

bool IsUSBDevice(const char* szDrivePath, bool& bRemovable) 
{ 
    if(GetDriveType(szDrivePath) != DRIVE_REMOVABLE) 
     return false; 

    HANDLE hDevice = CreateFile(szDrivePath,0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); 
    if(hDevice == INVALID_HANDLE_VALUE) 
     return false; 

    STORAGE_PROPERTY_QUERY pQuery = {0}; 
    pQuery.PropertyId = StorageDeviceProperty; 
    pQuery.QueryType = PropertyStandardQuery; 

    STORAGE_DEVICE_DESCRIPTOR pDeviceDesc = {0}; 
    pDeviceDesc.Size = sizeof(pDeviceDesc); 
    DWORD dwWritten = 0; 
    if(DeviceIoControl(hDevice,IOCTL_STORAGE_QUERY_PROPERTY,&pQuery,sizeof(STORAGE_PROPERTY_QUERY),pDeviceDesc,sizeof(pDeviceDesc),&dwWritten,NULL)) 
    { 
     CloseHandle(hDevice); 
     return ((bRemovable = pDeviceDesc.RemovableMedia) && pDeviceDesc.BusType == BusTypeUsb); 
    } 
    else 
     CloseHandle(hDevice); 

    return false; 
} 
+0

嗨...我需要過濾的USB設備接口類型 – user198725878 2010-07-01 12:52:31

+0

請查看底部的註釋和/或SetupDiGetDeviceRegistryProperty中的USB驅動器,DeviceIoControl也會給出一些關於刪除策略的信息等。 – Necrolis 2010-07-01 12:54:25

+0

你能告訴我一個驅動器號的示例 – user198725878 2010-07-01 13:07:38