如何获取设备序列号? [英] How to get hid device serial number?
本文介绍了如何获取设备序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想通过HID设备保护我的vb.net应用程序,所以我想在程序启动时检测具有特定ID的HID设备是否连接到计算机?我的HID设备是USB加密狗!我搜索了很多,我找到了很多代码,但没有什么对我的情况有用!
我尝试了什么:
进口 System.Management
< span class =code-keyword> Public Function GetHardwareSerialNumber_USB() As ArrayList
Dim ar As 新 ArrayList
Dim ms As ManagementObjectSearcher
Dim moReturn 作为 ManagementObjectCollection
Dim mo 作为 ManagementObject
ms = 新 ManagementObjectSearcher( < span class =code-string>从Win32_USBController中选择*)
moReturn = ms。获取()
对于 每个 mo 在 moReturn
ar.Add(mo( DeviceID))
下一步
返回 ar
结束 功能
解决方案
你可以运行来自C#的批处理命令并将序列号搜索到命令返回的文本中
wmic diskdrive get PNPDeviceID
I just want to protect my vb.net application via HID device so i want when the program starts, detect HID device with specific ID is connected to the computer or not? my HID device is a USB Dongle! i searched a lot and i found a lot of codes but nothing is useful for my case!
What I have tried:
Imports System.Management
Public Function GetHardwareSerialNumber_USB() As ArrayList
Dim ar As New ArrayList
Dim ms As ManagementObjectSearcher
Dim moReturn As ManagementObjectCollection
Dim mo As ManagementObject
ms = New ManagementObjectSearcher("Select * from Win32_USBController")
moReturn = ms.Get()
For Each mo In moReturn
ar.Add(mo("DeviceID"))
Next
Return ar
End Function
解决方案
you can run a batch command from C# and search the serial number into the text returned by the command
wmic diskdrive get PNPDeviceID
这篇关于如何获取设备序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文