Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB.NET
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
Posted
Updated 14-Feb-16 2:11am
v2
Comments
[no name] 14-Feb-16 7:56am    
I think "Serial number" is the Problem. You should better search for a HID device for a specific VID (Vendor ID) / PID (Product ID). For this you will find a lot of working examples www.

e.g.:
Scanning for a Human Interface Device (HID) using C# - Stack Overflow[^]

One more ting: In case you really using a dongle, why you don't use the Api of the dongle to connect to it? Cheating a VID/PID Usb device is easy and simply checking wheter there is a device with a specifif PID/VID connected, does not really protect your Software.
Maciej Los 14-Feb-16 8:13am    
Bruno, it sounds like an answer.
Cheers, Maciej.
[no name] 14-Feb-16 8:22am    
Hello Maciej
Let's say maybe half of an answer :)
Kind regards, Bruno
Richard MacCutchan 14-Feb-16 7:57am    
but nothing is useful for my case
Without an expalnation of what that means it is impossible to know what to suggest. Please edit your question and explain what results you receive against what you expect.
Member 11543248 14-Feb-16 8:11am    
i plugged my Dongle device into USB and run this code:
Dim USBDevicesClass As New System.Management.ManagementClass("Win32_USBController")
Dim ReturnUSBDevicesCollection As System.Management.ManagementObjectCollection = USBDevicesClass.GetInstances()
For Each USBDevice In ReturnUSBDevicesCollection

Dim objSearcher As New System.Management.ManagementObjectSearcher("Select * From Win32_PnPEntity where name = 'hid-compliant device'")
objReturnCollection = objSearcher.Get()
Next

Dim objReturn As System.Management.ManagementObject
For Each objReturn In objReturnCollection
Me.ListBox1.Items.Add(objReturn("deviceid").ToString())
Next

then i get two results:
(1)HID\VID_1A2C&PID_0C21&MI_01&COL02\8&11062B19&0&0001
(2)HID\VID_096E&PID_0006\7&230757ED&0&0000

1 solution

you can run a batch command from C# and search the serial number into the text returned by the command

Objective-C
wmic diskdrive get PNPDeviceID
 
Share this answer
 
v2
Comments
[no name] 14-Feb-16 9:29am    
Sorry, but this is not an answer, neutral 3.
Maciej Los 14-Feb-16 10:05am    
A tag of question is vb.net, not c#!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900