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