0

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

Does anybody have any suggestions, preferably something that would work across windows 7 and xp, I already tried the class posted here http://www.cfdan.com/posts/Retrieving_Non-Volatile_USB_Serial_Number_Using_C_Sharp.cfm however a serial number is never returned.

I understand that the serial number on a usb is optional but I have tried 3 separate usb sticks so I doubt this is the problem.

Community
  • 1
  • 1
brux
  • 3,197
  • 10
  • 44
  • 78

1 Answers1

0

From this post:

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());
}
keyboardP
  • 68,824
  • 13
  • 156
  • 205
  • this doesnt work for me, and its ManagementObjectSearcher not ManagementObjectSearch – brux May 11 '11 at 17:11
  • Yup, it was a typo and is now fixed. Either way, are you sure your USB sticks have serial numbers? Plus, this threads closed anyway so no one else can answer. – keyboardP May 11 '11 at 17:21