How to differentiate between USB flash drive and floppy

  • Thread starter Thread starter Kjetil Viggen
  • Start date Start date
K

Kjetil Viggen

I am currently using the System.IO.DriveInfo class to go through the
available drives on the system:

var drives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo drive in drives)
{
System.IO.DriveType type = drive.DriveType;
...
}

My problem is that I want to skip any floppy drives in this enumeration (Yes
- there are still systems with floppy drives out there...). However DriveType
does not help me do this. From the documentation on the DriveType enumeration:

" Removable:
The drive is a removable storage device, such as a floppy disk drive or a
USB flash drive."

WMI probably has some options to do differentiate between different
removable drive types, but my previous experience with WMI has shown severe
problems there when running as non-administrator users. So I am reluctant to
try this...

Another possible option is to just skip if drive letter is A: or B:, as
these are reserved for floppies. But the Windows Knowledge Base says:

"Drive letters A and B are reserved for floppy disk drives. However, if your
computer does not have a floppy disk drive, you can assign these letters to
removable drives."

So that is not exactly waterproof either...

How can I easily check if a given drive is a floppy drive or not?

Kjetil.
 
Mark Rae said:
I'm not even certain that WMI can help you unless there is actual media in
the drive:
http://msdn.microsoft.com/en-us/library/aa394173(VS.85).aspx

Did a quick WMI-test using Win32_LogicalDisk and without any floppy in the
drive:
Description: 3 1/2 Inch Floppy Drive
DeviceID: A:

This looks sort of promising, but can I trust that all floppy drives come up
with a description like this...?
And what about a USB floppy...?

Well, I would certainly like to detect that as a floppy too, so for me it is
not sufficient just to see that a given drive letter represents a USB-device.

Kjetil
 
Mark Rae said:
There is, however, a dedicated WMI newsgroup
(microsoft.public.dotnet.framework.wmi) where you will probably get a much
better answer...

Thanks Mark, I'll try a post there and see what happens.

Kjetil.
 
One of the problems with USB is how screwed up the standard is, IMO. I had
to use it to iterate through a device that took 8 serial ports into a single
USB. It may be easier for drives. There are some Windows calls you can
PInvoke for drives. I am not sure how much info you can get.
Win32_LogicalDiskToPartition and Win32_DiskDrive are a couple that might be
useful. Sometime you end up having to search the registry for more
information; I did with the Serial device.

I am not sure about flash drives and USB floppies, but I did find the serial
port devices were rather specific in how they were set up in the Registry.
Unfortunately, I had to know a bit too much about the device and alter my
config files for each one. I would assume USB drives are easier, but I
cannot guarantee it. Good luck on this one.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

********************************************************
| Think outside the box! |
********************************************************
 
Back
Top