views:

89

answers:

2

Hi, I'm trying to differentiate between a USB flash drive and a USB hard drive on Windows using the Win32 API.

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

Thanks in advance.

A: 

Actually windows doesn't, GetDriveType returns 3 (DRIVE_FIXED) for both my usb hard-drives.

monoceres
No kidding, thanks. And your USB hard drives are run-of-the-mill, and there are no special driver settings or anything like that that might cause Windows to consider them DRIVE_FIXED instead of DRIVE_REMOVABLE?
They're just standard western digital drives and my windows installation is pretty fresh so nothing on the driver front has changed from the default settings.
monoceres
A: 

The drive type is ultimately determined by the drivers; there's no fail-safe way to make the sort of determination that you're looking for.

I can say, however, that while I have seen a USB flash stick return DRIVE_FIXED, I have never seen a normal hard drive return DRIVE_REMOVEABLE. That's not to say that it's completely impossible for that to happen, but I've never seen it.

I'd say relying on those two values is probably the closest that you're going to get.

Adam Robinson
Interesting you say you've seen a flash stick return DRIVE_FIXED, as I found this a few minutes before reading your comment: http://social.msdn.microsoft.com/forums/en-US/embeddedwindowscomponents/thread/cfffc7b6-5679-46fc-a1c9-4c08228b7b47/