Differentiation between a USB drive and a USB hard drive in Windows

I am trying to distinguish between a USB drive and a USB hard drive in Windows using the Win32 API.

The GetDriveType () function will return DRIVE_REMOVABLE if the drive is removable and the USB drives are, of course, removable. But I think that Windows probably also considers removable USB drives (unfortunately, I don't have access to a USB hard drive to check it out).

Thanks in advance.

+5
source share
7 answers

Windows DRIVE_FIXED USB DRIVE_REMOVABLE - USB. , -, , , DRIVE_REMOVABLE, DRIVE_FIXED. Windows "" -, ESXi usb stick, -)

+1

, USB, IOCTL DeviceIoControl(), , .

EnumUsbDrivesLetters - , ++, .

Cheers,

+1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Method      OpenVolume
//  Purpose:    Open volume for removal. Change to ::CreateFile(volumeName, 0, 0, 0, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, 0);
//              if you just want to inquire if it removable. 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

HANDLE OpenVolume(const char& driveLetter)
{
    char volumeName[8] = "";
    char* volumeFormat = "\\\\.\\%c:";
    sprintf(volumeName, volumeFormat, driveLetter);

    HANDLE volume = ::CreateFile(volumeName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    if (volume == INVALID_HANDLE_VALUE) return INVALID_HANDLE_VALUE;

    DWORD bytesReturned = 0;
    STORAGE_HOTPLUG_INFO Info = {0};
    if (::DeviceIoControl(volume, IOCTL_STORAGE_GET_HOTPLUG_INFO, 0, 0, &Info, sizeof(Info), &bytesReturned, NULL)) 
    {
        if (!(Info.MediaRemovable || Info.DeviceHotplug)) 
        {
            ::CloseHandle(volume);
            ::SetLastError(ERROR_INVALID_PARAMETER);
            return INVALID_HANDLE_VALUE;
        }
    }

    return volume;
}
+1

, GetDriveType 3 (DRIVE_FIXED) usb.

0

; , .

, , , USB-- DRIVE_FIXED, DRIVE_REMOVEABLE. , , .

, , , , .

0

http://en.wikipedia.org/wiki/SCSI_Pass_Through_Interface SCSI - INQUIRY MODE SENSE, , . API VDS, ( , )

0

All Articles