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.
- //You can generate and get your public key via toolbox. Never add private key into your source code.
- private const string MyPublicKey = "Put your PUBLIC key XML here.";
- private TreeksLicensingLibrary.LicenseVerification verification = new TreeksLicensingLibrary.LicenseVerification(MyPublicKey);
- // string ErrorMessage returns more detailed info on why was license recognized as invalid
- // LicenseObject contains information about license, like owner, expiration date (if any), etc.
- public bool IsLicenseValid(ref string ErrorMessage = "", ref TreeksLicensingLibrary.License LicenseObject = null)
- {
- string LicenseFilePath = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) + "\\registration.lic";
- if (IO.FileExists(LicenseFilePath)) {
- if (verification.VerifyLicenseFile(LicenseFilePath, ErrorMessage, LicenseObject)) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- 'You can generate and get your public key via toolbox. Never add private key into your source code.
- Private Const MyPublicKey As String = "Put your PUBLIC key XML here."
- Private verification As New TreeksLicensingLibrary.LicenseVerification(MyPublicKey)
- ' String ErrorMessage returns more detailed info on why was license recognized as invalid
- ' LicenseObject contains information about license, like owner, expiration date (if any), etc.
- Public Function IsLicenseValid(Optional ByRef ErrorMessage As String = "", Optional ByRef LicenseObject As TreeksLicensingLibrary.License = Nothing) As Boolean
- Dim LicenseFilePath As String = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) & "\registration.lic"
- If IO.FileExists(LicenseFilePath) Then
- If verification.VerifyLicenseFile(LicenseFilePath, ErrorMessage, LicenseObject) Then
- Return True
- Else
- Return False
- End If
- Else
- Return False
- End If
- End Function
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- 'This is Office VBA (Visual Basic for Applications) example '
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Public Function CheckLicenceIsValid() As Boolean
- 'Initialize new instances of TLL objects
- Dim objVerification As New TreeksLicensingLibrary.LicenseVerification
- 'This object will be loaded with details from license file
- Dim objLicenseObject As New TreeksLicensingLibrary.License
- 'Declare working variables
- Dim blnValid As Boolean
- Dim strLicenseFilePath As String
- '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
- Dim strErrorMessage As String
- 'Change this public key to yours, you can generate it in LibraryToolbox.exe
- objVerification.SetPublicKey "YourPublicKey"
- 'Change this path to yours
- strLicenseFilePath = "d:\test.lic"
- blnValid = objVerification.VerifyLicenseFile(strLicenseFilePath, strErrorMessage, objLicenseObject)
- If blnValid = True Then
- 'Show info about valid license
- MsgBox "Licence is Valid." & vbCr & vbLf & vbCr & vbLf & "Product: " & objLicenseObject.ProductName & vbCr & vbLf & "License owner: " & objLicenseObject.OwnerName
- Else
- 'Show info about invalid license
- MsgBox "Licence is Not Valid." & vbCr & vbLf & vbCr & vbLf & "Reason: " & strErrorMessage & vbCr & vbLf & vbCr & vbLf & "Contact Support"
- End If
- End Function