There is no separate VB binding to learn: KeyNub.LicenseDongle is a .NET assembly, so VB.NET consumes exactly the same package as C# and F#. What differs is the call style, and for interop that difference is worth being deliberate about.
dotnet add package KeyNub.LicenseDongleCode language: Bash (bash)
Reading a license
Option Strict On
Imports KeyNub.LicenseDongle
Using ctx As LicenseDongleContext = LicenseDongleContext.Create()
Dim devices = ctx.Enumerate()
If devices.Count = 0 Then
Console.WriteLine("Please plug in your KeyNub license dongle.")
Return 0
End If
Using dongle As Dongle = ctx.Open() ' first dongle found
dongle.VerifyGenuine() ' throws unless genuine
Using session As Session = dongle.OpenSession()
Dim licence As Byte() = session.ReadRecord("license")
End Using
End Using
End UsingCode language: VB.NET (vbnet)
Turn Option Strict on
Some tooling still creates VB projects with Option Strict Off. For code that talks to hardware through a native library, that is exactly the wrong default: a silent narrowing conversion of a byte array, a handle or a length is the class of bug that shows up as corruption at a customer site rather than as a compile error on your machine. The sample sets <OptionStrict>On</OptionStrict> in the project file, and we would recommend the same in yours.
The nested Using blocks are doing real work: each one closes its resource on every exit path, including when an exception unwinds. The dongle driver keeps a small fixed table of open handles, and a leaked one becomes a support call weeks later.
Do not gate on a boolean
A .NET assembly decompiles into readable source, and an If licensed is one IL instruction away from If True. Obfuscation raises the effort; it does not remove the branch. Make the program need something only the dongle can produce:
' Weak -- a branch a patcher removes.
If isLicensed Then EnableFeature()
' Strong -- the values only exist when the dongle does.
Dim coefficients As Byte() = session.AppDecrypt(EncryptedBlobFromInstaller)Code language: VB.NET (vbnet)
Full VB.NET sample on GitHub · the same thing in C# · in F#
All supported languages · All industries · Buy a KeyNub · Ask us something