[c#]从usb密钥获取序列号 [英] [c#] get the serial number from a usb key
本文介绍了[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 classWin32_LogicalDisk
, it has one property calledVolumeSerialNumber
. Other properties likeDriveType
andMediaType
will help you identifying the type or drive. With the propertyPNPDeviceID
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屋!
查看全文