# [C# Net 3.5] DriveInfo class



## Emphyrio (May 16, 2009)

I was wondering why _DriveType_ in *DriveInfo* doesn't give me what is says.



> // .........DriveType................
> // Unknown, The type of drive is unknown.
> // NoRootDirectory,The drive does not have a root directory.
> // Removable, The drive is a removable storage device,
> ...


If I put that into code....


```
public void showHD()
{
string tmpHD = ""; // temp for HD info output.
try
    {
       DriveInfo[] allDrives = DriveInfo.GetDrives();
       foreach (DriveInfo drv in allDrives)
        {
          if (drv.IsReady == true)
           {
             tmpHD += (drv.Name +" "+ drv.VolumeLabel + " - " + drv.DriveType;
            }
         }
   }
catch (ArgumentNullException)
       {
         // nothing there
        }
MessageBox.Show(tmpHD);
}
```
I have a External USB 2.0 HD connected and running and it shows as "Fixed" and not "Removable".

Did I overlooked something?


----------



## Ninjaboi (Dec 27, 2010)

Hello Emphyrio!

I don't think you overlooked anything actually. I also have an external USB 2.0 hard drive here, and it shows as a "Local Drive" ( which my local C:\ drive also shows this, so that might mean that it's a "Fixed" drive ). Try a USB flash drive and see if you get "Removable".


----------



## Emphyrio (May 16, 2009)

Hoi Ninjaboi :wave:

Yes, a USB Flashdrive shows as Removable.
Is there a know way to intercept this, somewhat incorrect, output?


----------



## Ninjaboi (Dec 27, 2010)

*Unknown*:
The type of drive is unknown.

*NoRootDirectory*:
The drive does not have a root directory.

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

*Fixed*:
The drive is a fixed disk.

*Network*:
The drive is a network drive.

*CDRom*:
The drive is an optical disc device, such as a CD or DVD-ROM.

*Ram*:
The drive is a RAM disk.




The external hard drive you have must be 'Fixed' because inside it has a fixed disk that revolves and stores memory rather than flash memory ( thus not being an external 'flash' drive ). So, it seems that's why DriveInfo returns this value to your program, because the drive you inserted first was using 'hard' memory rather than 'flash' memory.

Incorrect to what we usually think ( I sometimes think it to if I don't catch myself ) is that we believe if a drive uses a USB cable then it must be flash memory. This is probably because we feel that a 'removable' drive is something that we can easily insert and remove. Since flash drives are the most common item that uses USB cables for storage data transfer, we assocaite the attributes of a flash drive with any other device that does storage data tranfer via a USB cable.

*Source(s):*

Thoughts.exe » Blog Archive » Detecting removable drive types using C#
Universal Serial Bus - Wikipedia, the free encyclopedia


----------



## Emphyrio (May 16, 2009)

I see you point and you are correct.

But, even Microsoft is a bit confusing here by stating in their systray tool "Safely Removable Hardware" the USB HD in question as a _Removable Device for Mass Storage_.










If I could catch that, then I could output the "correct" description.

(Thanks for your time, Ninjaboi)


----------



## Ninjaboi (Dec 27, 2010)

Hm...when you put in a USB flash drive, does it also fall under the same category in the systray tool? If so, this is very odd that Microsoft's tool would put them under the same category. I might need someone from Hardware here at TSF to check this out and perhaps give better insight on external storage.



> (Thanks for your time, Ninjaboi)


You're welcome, always glad to help.


----------



## Emphyrio (May 16, 2009)

Yes, they both in the same category "Mass Storage"










Its getting even odder  
Under Device Manager they both listed under Storage Discs (and not HID, USB or HUB)


----------



## Ninjaboi (Dec 27, 2010)

I got a bit more insight from two kind people from Hardware. 

They stated that all USB drives are treated as 'Removable', which means it might be the settings on your particular machine that's causing this problem. One of them suggested that you try your application on a different machine ( preferably one with a fresh install and update ) to check if it's your machine's settings that cause the problem. If it does, then you might need to work out and deduce what you have to make your program do in situations where the machine settings categorize such an external device in the wrong category.

That's coming straight from Hardware, so they would know best as far as something like this.


----------



## Emphyrio (May 16, 2009)

Thankyou, Ninjaboi :=)

I shall test it on my VMWare W7 x64 and XP :=)


----------

