BOOL IsUsbDevice(TCHAR letter) { TCHAR volumeAccessPath[] = _T("\\\\.\\X:"); volumeAccessPath[4] = letter; HANDLE deviceHandle = CreateFile( volumeAccessPath, 0, // no access to the drive FILE_SHARE_READ | // share mode FILE_SHARE_WRITE, NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // do not copy file attributes // setup query STORAGE_PROPERTY_QUERY query; memset(&query, 0, sizeof(query)); query.PropertyId = StorageDeviceProperty; query.QueryType = PropertyStandardQuery; // issue query DWORD bytes; STORAGE_DEVICE_DESCRIPTOR devd; STORAGE_BUS_TYPE busType = BusTypeUnknown; if (DeviceIoControl(deviceHandle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &devd, sizeof(devd), &bytes, NULL)) { busType = devd.BusType; } else { //std::wcout << L"Failed to define bus type for: " << letter; } CloseHandle(deviceHandle); return BusTypeUsb == busType; }
C++
USB
query
윈도우
장치
Retrieved from http://hyacinth.byus.net/moniwiki/wiki.php/C++/IsUsbDevice
last modified 2013-02-20 17:49:58