ytw
ytw

Reputation: 1355

How to use C# to retrieve the Manufacturer property of a flash drive

I need to retrieve the Manufacturer property of a flash drive using the C# programming language. I tried the suggested solution here (how to determine USB Flash drive manufacturer?), but that doesn't seem to work. I got 'Standard disk drives' for the Manufacturer property. Does anyone know how to get the value 'SanDisk' for the Manufacturer property as seen below in C#?

enter image description here

Upvotes: 4

Views: 2221

Answers (1)

eandersson
eandersson

Reputation: 26352

You should be able to do something simple like this to get the Manufacturer data assuming that it contains something besides the generic (Standard disk drives)

ManagementObjectSearcher search = new
    ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

foreach(ManagementObject wmi in search.Get())
{
    Console.WriteLine(wmi["Manufacturer"].ToString());
}

You would need to add a reference to System.Management in your project to be able to use these functions as well.

As an alternative you could use a hack, basically get the name of the Model and split it so that you only take the Manufacturer name.

Console.WriteLine(wmi["Model"].ToString().Split()[0]);

Upvotes: 5

Related Questions