3

How to get name of usb drive attahced to my Windows ce device using c# or any or the native API.

Anant
  • 342
  • 6
  • 14

2 Answers2

0

The folder name is localized and can change from device to device. The way I do it is to query it from the same registry location the driver used for getting the name:

using(var key = Registry.LocalMachine.OpenSubKey(
                @"\System\StorageManager\Profiles\USBHDProfile"))
{
    USBDiskFolderName = key.GetValue("Folder").ToString();
}
ctacke
  • 66,480
  • 18
  • 94
  • 155
  • It shows name as 'Removable Disk'. What i want is; if i have named usb to say "Anant" so name should be detected as it is i.e. Anant. But it shows 'Removable Disk' always. My query is do system image of platform plays part in this; meeans the way it is shown to user?? – Anant Dec 26 '12 at 12:16
  • So you want to change the name of the mounted folder, or are you trying to get the label assigned to the drive when it was formatted? The folder name that is mounted is set when you build the OS image. – ctacke Dec 26 '12 at 13:28
0

You may be able to start with the C# DriveInfo class:

    DriveInfo[] allDrives = DriveInfo.GetDrives();

    foreach (DriveInfo d in allDrives)
    {
        Console.WriteLine("Drive {0}", d.Name);
        Console.WriteLine("  File type: {0}", d.DriveType);
        if (d.IsReady == true)
        {
            Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
            Console.WriteLine("  File system: {0}", d.DriveFormat);
            Console.WriteLine(
                "  Available space to current user:{0, 15} bytes", 
                d.AvailableFreeSpace);

            Console.WriteLine(
                "  Total available space:          {0, 15} bytes",
                d.TotalFreeSpace);

            Console.WriteLine(
                "  Total size of drive:            {0, 15} bytes ",
                d.TotalSize);
        }
    }

http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx

or this may help:

Get List of connected USB Devices

Community
  • 1
  • 1
Brissles
  • 3,833
  • 23
  • 31