I have to write a function that returns all drive letters where the drive is a USB stick. The problem is that the USB sticks might be partitioned in way that Windows assigns 2 or more Drives to a single USB stick of which only one is a USB mass storage device(that is the letter that I want). So stuff like
DriveInfo.GetDrives()
and then filtering with device.DriveType == DriveType.Removable
does not work because that returns all the drives that are removable.
I have been trying to do it in WMI but so far I have not found the right answer. The most common answer to similiar questions is to go throug a few classes like this (source):
Win32_DiskDrive-> Win32_DiskDriveToDiskPartition -> Win32_DiskPartition -> Win32_LogicalDiskToPartition -> Win32_LogicalDisk
But that also returns all drives of the USB sticks. My thinking would be to remove all the drives that are not mass storage devices with Win32_USBHub
. But I don't know where to add it in the chain or if that is even possible? Any help?