This function loads file registration.lic from your application location (for example: C:\Program Files\YourApp\registration.lic) and checks its validity. You can change location of file or use VerifyLicenseXML function of TreeksLicensingLibrary.LicenseVerification object.

  1. //You can generate and get your public key via toolbox. Never add private key into your source code.
  2. private const string MyPublicKey = "Put your PUBLIC key XML here.";
  3.  
  4. private TreeksLicensingLibrary.LicenseVerification verification = new TreeksLicensingLibrary.LicenseVerification(MyPublicKey);
  5.  
  6. // string ErrorMessage returns more detailed info on why was license recognized as invalid
  7. // LicenseObject contains information about license, like owner, expiration date (if any), etc.
  8. public bool IsLicenseValid(ref string ErrorMessage = "", ref TreeksLicensingLibrary.License LicenseObject = null)
  9. {
  10.  
  11.     string LicenseFilePath = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) + "\\registration.lic";
  12.  
  13.     if (IO.FileExists(LicenseFilePath)) {
  14.         if (verification.VerifyLicenseFile(LicenseFilePath, ErrorMessage, LicenseObject)) {
  15.             return true;
  16.         } else {
  17.             return false;
  18.         }
  19.     } else {
  20.         return false;
  21.     }
  22.  
  23. }
  1. 'You can generate and get your public key via toolbox. Never add private key into your source code.
  2. Private Const MyPublicKey As String = "Put your PUBLIC key XML here."
  3. Private verification As New TreeksLicensingLibrary.LicenseVerification(MyPublicKey)
  4.  
  5. ' String ErrorMessage returns more detailed info on why was license recognized as invalid
  6. ' LicenseObject contains information about license, like owner, expiration date (if any), etc.
  7. Public Function IsLicenseValid(Optional ByRef ErrorMessage As String = "", Optional ByRef LicenseObject As TreeksLicensingLibrary.License = Nothing) As Boolean
  8.  
  9. Dim LicenseFilePath As String = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) & "\registration.lic"
  10.  
  11. If IO.FileExists(LicenseFilePath) Then
  12.     If verification.VerifyLicenseFile(LicenseFilePath, ErrorMessage, LicenseObject) Then
  13.         Return True
  14.     Else
  15.         Return False
  16.     End If
  17. Else
  18.     Return False
  19. End If
  20.  
  21. End Function
  1. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  2. 'This is Office VBA (Visual Basic for Applications) example   '
  3. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4. Public Function CheckLicenceIsValid() As Boolean
  5.    
  6.     'Initialize new instances of TLL objects
  7.    Dim objVerification As New TreeksLicensingLibrary.LicenseVerification
  8.     'This object will be loaded with details from license file
  9.    Dim objLicenseObject As New TreeksLicensingLibrary.License
  10.    
  11.     'Declare working variables
  12.    Dim blnValid As Boolean
  13.     Dim strLicenseFilePath As String
  14.    
  15.     'This variable will contain error details when verification fails. In the other words, it'll tell you why the license file was recognized as invalid. Will be empty on verification success
  16.    Dim strErrorMessage As String
  17.    
  18.    
  19.     'Change this public key to yours, you can generate it in LibraryToolbox.exe
  20.    objVerification.SetPublicKey "YourPublicKey"
  21.      
  22.     'Change this path to yours
  23.    strLicenseFilePath = "d:\test.lic"
  24.    
  25.     blnValid = objVerification.VerifyLicenseFile(strLicenseFilePath, strErrorMessage, objLicenseObject)
  26.  
  27.     If blnValid = True Then
  28.          'Show info about valid license
  29.         MsgBox "Licence is Valid." & vbCr & vbLf & vbCr & vbLf & "Product: " & objLicenseObject.ProductName & vbCr & vbLf & "License owner: " & objLicenseObject.OwnerName
  30.     Else
  31.          'Show info about invalid license
  32.         MsgBox "Licence is Not Valid." & vbCr & vbLf & vbCr & vbLf & "Reason: " & strErrorMessage & vbCr & vbLf & vbCr & vbLf & "Contact Support"
  33.     End If
  34.  
  35. End Function