How do I get the internal serial number of a USB-Stick or USB-HardDrive in C#?
Asked
Active
Viewed 3.7k times
3 Answers
34
Try this:
// add a reference to the System.Management assembly and
// import the System.Management namespace at the top in your "using" statement.
// Then in a method, or on a button click:
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'");
foreach (ManagementObject currentObject in theSearcher.Get())
{
ManagementObject theSerialNumberObjectQuery = new ManagementObject("Win32_PhysicalMedia.Tag='" + currentObject["DeviceID"] + "'");
MessageBox.Show(theSerialNumberObjectQuery["SerialNumber"].ToString());
}

Marcel Popescu
- 3,146
- 3
- 35
- 42

Yuval Adam
- 161,610
- 92
- 305
- 395
-
great job i got serial number how do i get instance id of the usb. – KVK Jun 24 '14 at 05:57
9
A solution using Win32 is described here
Edit: the original link seems to have gone missing. The above is a cached copy, and the author also wrote some sample code in VB.Net which is still online here.

41686d6564 stands w. Palestine
- 19,168
- 12
- 41
- 79

James L
- 16,456
- 10
- 53
- 70
7
I had problems with the solution offered by Yuval Adam as every USB stick I tried return blank on windows 7.
I solved this by just looking at the property PNPDeviceId on the current object.
E.g.
currentObject["PNPDeviceID"].ToString();
Not sure how valid this is but it worked for me on the 3 USB Sticks I tried