It was easier than I thought ...
Imports Microsoft.Win32
Imports System.Text.RegularExpressions
Public Class ReaderInfo
Public DriverExists As Boolean
Public PortName As String
Public PortExists As Boolean
Public PortOpened As Boolean
Public VendorID As String
Public ProduktID As String
Public DriverID As String
Public Description As String
Public Typ_Converter As String
Public Typ_Reader As String
Sub Clear()
DriverExists = False
PortName = ""
PortExists = False
PortOpened = False
VendorID = ""
ProduktID = ""
Description = ""
Typ_Converter = ""
Typ_Reader = "Kaba B-Net 9107 Card-Reader"
End Sub
Sub New()
Clear()
End Sub
Public Sub Get_RegistryInfo(VID As String, PID As String)
Dim rk1 As RegistryKey = Registry.LocalMachine
Dim rk2 As RegistryKey = rk1.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum")
Clear()
VendorID = VID
ProduktID = PID
Dim pattern As String = String.Format("^VID_{0}.PID_{1}", VID, PID)
Dim _rx As Regex = New Regex(pattern, RegexOptions.IgnoreCase)
Dim rk2_SubKeyNames, rk3_SubKeyNames, rk4_SubKeyNames As String
Dim Desc, Mfg As String
Dim Index As Integer
For Each rk2_SubKeyNames In rk2.GetSubKeyNames()
Dim rk3 As RegistryKey = rk2.OpenSubKey(rk2_SubKeyNames)
For Each rk3_SubKeyNames In rk3.GetSubKeyNames()
If _rx.Match(rk3_SubKeyNames).Success Then
Dim rk4 As RegistryKey = rk3.OpenSubKey(rk3_SubKeyNames)
DriverExists = True
For Each rk4_SubKeyNames In rk4.GetSubKeyNames()
Index = CInt(rk4_SubKeyNames)
Dim rk5 As RegistryKey = rk4.OpenSubKey(rk4_SubKeyNames)
If rk5.OpenSubKey("Control") IsNot Nothing Then
Dim rk6 As RegistryKey = rk5.OpenSubKey("Device Parameters")
Dim rk5_DeviceDesc As String() = rk5.GetValue("DeviceDesc").ToString.Split(";")
Desc = rk5_DeviceDesc(rk5_DeviceDesc.Length - 1)
If Index = 0 Then
Description = Desc
PortName = rk6.GetValue("PortName")
Dim myComports As String() = System.IO.Ports.SerialPort.GetPortNames()
For i As Integer = 1 To myComports.Length
If myComports(i - 1) = PortName Then
PortExists = True
Exit For
End If
Next
Else
Dim rk5_Mfg As String() = rk5.GetValue("Mfg").ToString.Split(";")
Mfg = rk5_Mfg(rk5_Mfg.Length - 1)
Typ_Converter = Mfg + vbCrLf + Desc
DriverID = Index.ToString
End If
End If
Next
End If
Next
Next
End Sub
End Class
of course ... the sample is VB - but I think you could see how it works. Should I convert it to C# ?
The only Thing is to know the Vendor-ID and the Product-ID. With this Information you call the Method "Get_RegistryInfo"
I hope, it helps - otherwise feel free to contact me again ...