How to get serial number of USB-Stick in C#

Xn0vv3r picture Xn0vv3r · Jan 16, 2009 · Viewed 33.5k times · Source

How do I get the internal serial number of a USB-Stick or USB-HardDrive in C#?

Answer

Yuval Adam picture Yuval Adam · Jan 16, 2009

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());
}

Source: http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/f4447ed3-7e5f-4635-a28a-afff0b620156/