Home > DeveloperSection > Forums > Get the USB Flash drive manufacturer using C#?
C G E Mannerheim
C G E Mannerheim

Total Post:29

Points:203
Posted on    October-16-2013 7:14 AM

 C# C# 
Ratings:


 1 Reply(s)
 2616  View(s)
Rate this:

How can I get the manufacture of USB Flash drive using C#?



Hugh Jackman
Hugh Jackman

Total Post:52

Points:366
Posted on    October-16-2013 7:46 AM

Below is example works for you. It uses WMI.

Console.WriteLine("Manufacturer: {0}", queryObj["Manufacturer"]);
Console.WriteLine("Name: {0}", c["Name"]); // here it will print drive letter

The full code sample:

namespace WMISample
{
    using System;
    using System.Management;
 
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_DiskDrive");
 
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
                    Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);
                    Console.WriteLine("Manufacturer: {0}", queryObj["Manufacturer"]);
                    Console.WriteLine("Model: {0}", queryObj["Model"]);
                    foreach (ManagementObject b in queryObj.GetRelated("Win32_DiskPartition"))
                    {
                        Console.WriteLine("  Name: {0}", b["Name"]);
                        foreach (ManagementBaseObject c in b.GetRelated("Win32_LogicalDisk"))
                        {
                            Console.WriteLine("    Name: {0}", c["Name"]); // here it will print drive letter
                        }
                    }
                    // ...
                    Console.WriteLine("--------------------------------------------");
                }      
            }
            catch (ManagementException e)
            {
                Console.WriteLine(e.StackTrace);
            }
 
            Console.ReadLine();
        }
    }
}

 


Don't want to miss updates? Please click the below button!

Follow MindStick