Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

usb

usb-drive

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

like image 340
Xn0vv3r Avatar asked Jan 16 '09 10:01

Xn0vv3r


People also ask

How do I find my USB serial number?

Each USB hardware device has a unique serial number that is required during the activation process. To locate the serial number of a key, turn the key to the side opposite the colored label. You see three rows of numbers. The lowest or bottom row of numbers is the serial number.

How do I identify a USB stick?

Coming to USB 3.0 pen drives, you'll see a prominent difference from the USB 2.0 and older drives, with USB 3.0, USB-SS or USB Super Speed usually written on the pen drives. As a general rule, can identify USB stick version visually. Have a look at the inner part of the USB plug and look at the color.

How do I find my USB serial number Ubuntu?

You can use lsusb , but you need to add verbose flag and make sure you use sudo with it, otherwise the serial will be incorrect. Then run lsusb with device flag and grep the serial number.

Where are USB devices stored in the registry?

Windows registry stores information about each USB connected device in the following registry keys: 1. HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\ENUM\USBSTOR: This key keeps a list of all USB storage devices that have ever been plugged into the system.


1 Answers

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/

like image 135
Yuval Adam Avatar answered Oct 05 '22 20:10

Yuval Adam