carls
4Penny.net
Points: 3300

11/16/2018 9:47:46 AM

Application that creates a license key for your applications

* This article, and all our great .NET Development documentation, Is available on the .NET Development menu

This piece of code is ALL the code behind for a standard .net 1 form application that generates a license key that can be used by your applications. 

The form looks like this:

And, here is the code that consumes the key:

    Private Sub ProcessLicenseKey()
 
        ' This subroutine reads the distribution key, decrypts it, extracts the
        ' expiration date, and warns as expiration is within 2 months, and exits
        ' if expiration is past.
        Dim baseDir = Path.GetDirectoryName(Application.ExecutablePath)
        Dim expirationDate As DateTime
        Dim keyValid As Boolean = True
 
        Try
            Dim encryptedText As String = File.ReadAllText(Path.Combine(baseDir, "KEY.DAT"))
            Dim licenseKey As LicenseKey = New LicenseKey()
            expirationDate = licenseKey.GetExpirationDate(encryptedText)
            If Not (ValidKey(expirationDate)) Then
                Application.Exit()
            End If
 
        Catch ex As FileNotFoundException
            Dim msg As String = "Unable to read distribution key." + vbCrLf
            msg += String.Format("Error: {0}", ex.Message) + vbCrLf
            msg += "Contact your Run-Biz representative." + vbCrLf
            msg += "Program will be terminated."
            MessageBox.Show(msg)
            keyValid = False
 
        Catch ex As Exception
            Dim msg As String = "Unexpected error occurred." + vbCrLf
            msg += String.Format("Error: {0}", ex.Message) + vbCrLf
            msg += "Contact your Run-Biz representative." + vbCrLf
            msg += "Program will be terminated."
            MessageBox.Show(msg)
            keyValid = False
 
        End Try
 
        If Not keyValid Then
            Application.Exit()
        End If
 
    End Sub
End Class

 

4Penny.net
Version: Unknown or N/A
Section: .NET Development
Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3