[c#]从usb密钥获取序列号 [英] [c#] get the serial number from a usb key

查看:311
本文介绍了[c#]从usb密钥获取序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得连接到PC的USB密钥的序列号,型号......?


这样的东西:

 ManagementObjectSearcher USB =  new  ManagementObjectSearcher(  SELECT * FROM Win32_DiskDrive); 
ManagementObjectCollection USBinfo = USB.Get();
string info = ;
foreach (ManagementObject MO in USBinfo)
{
info = ( string )MO [ SerialNumber ]。
}





但这给了我磁盘的序列号,而不是usb密钥。

解决方案

请参阅: http:// msdn.microsoft.com/en-us/library/windows/hardware/hh998535.aspx [ ^ ]。



-SA

尝试查询 WMI Win32_LogicalDisk ,它有一个名为 VolumeSerialNumber的属性。其他属性(如 DriveType MediaType )将帮助您识别类型或驱动器。使用属性 PNPDeviceID ,可以将其追踪到物理USB设备信息。

这里有一个很长的讨论http://social .technet.microsoft.com /论坛/ windowsserver / en-US / 09c9814a-38fa-4b16-bc8f-01329882a791 / powershell-wmi-get-usb-storage-devices-only [ ^ ]提示可以提供帮助。


How to get the serial number, model,... of the usb key connected on to pc?

Something like this:

ManagementObjectSearcher USB = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
          ManagementObjectCollection USBinfo = USB.Get();
          string info = "";
          foreach (ManagementObject MO in USBinfo)
          {
              info = (string)MO["SerialNumber"];
          }



But this gives me the serial number for disk, not usb key.

解决方案

Please see: http://msdn.microsoft.com/en-us/library/windows/hardware/hh998535.aspx[^].

—SA


Try querying for the WMI class Win32_LogicalDisk, it has one property called VolumeSerialNumber. Other properties like DriveType and MediaType will help you identifying the type or drive. With the property PNPDeviceID it could be possible to track it down to the physical USB device information.
There's a long disccussion here http://social.technet.microsoft.com/Forums/windowsserver/en-US/09c9814a-38fa-4b16-bc8f-01329882a791/powershell-wmi-get-usb-storage-devices-only[^] with hints that could help.


这篇关于[c#]从usb密钥获取序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆