如何在C#中获取USB-Stick的序列号

如何在C#中获取USB-Stick或USB-HardDrive的内部序列号?

试试这个:

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

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

这里描述了使用Win32的解决方案

编辑:原始链接似乎已经丢失。 以上是一个缓存副本,作者还在VB.Net中编写了一些示例代码,这些代码仍然在线 。

我遇到了Yuval Adam提供的解决方案的问题,因为我试过的每个USB记忆棒在Windows 7上都是空白的。

我通过查看当前对象上的属性PNPDeviceId来解决这个问题。

例如

 currentObject["PNPDeviceID"].ToString(); 

不知道这是多么有效,但它在我试过的3个USB棒上对我有用