Hello guys, I have made an application in which I want to make my application expired after 6 months. and then user enters a key to activate and then application again validates for another 6 months.

My code is:

Public Class Form8
    Dim date1 As Date = #7/24/2012 9:00:00 PM#
    Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Now As DateTime = DateTime.Now

        Dim result As Integer = DateTime.Compare(Now, date1)

        If result <= 0 Then
            MessageBox.Show("This Tool has been Expired, Please enter valid Key to continue.", "Expired...",   
            MessageBoxButtons.OK, MessageBoxIcon.Error)

        End If
    End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If TextBox1.Text = "asdfghjkl" Then
            date1 = #1/24/2013 10:00:00 PM#
            MessageBox.Show("Congratulations...!! Your Product has been validated for next 6 months", "Activated...", 
            MessageBoxButtons.OK, MessageBoxIcon.Information)
            Form8_Load(sender, e)
            MessageBox.Show("Invalid Key", "Expired...", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub
End Class

Everything is working fine but the problem is after 6 mnths when the current time is greater then the mentioned time and when user enters the key, user have to enter the key for every use.
Please tell me how can i set date1 so that it can be set for every use.

4 Years
Discussion Span
Last Post by Begginnerdev

You will need to write a function/sub that will refresh the expiration date on key entry.

Something Like:

Private Sub RefreshDates(ByVal sKey As String)
    If isAuthenticated(sKey) Then
        Me.Date1 = Now.AddMonths(6)
    End If
End Sub

Private Function isAuthenticated(ByVal key As String) As Boolean
    'validate key and return true here
End Function

Edited by Begginnerdev


But even this function will set the expiration date on every use.
How to refresh date only once so that once user has entered a valid key, the application runs normally.


You will only call the function when a key needs to be entered.

If you are wanting only one renew ( for a total life of one year )

Then you can think about the situation from the other way.

Set Date1 to 1 year from the first use, and at the 6 month place, ask for another key.


Also, another suggestion. Instead of using the value stored in the program ( Value will remain the same after refresh when the application is reloaded. ) think about using registry keys or application settings.

The only issue with these are if the user finds them, they can simply edit them to add more time...

You will have to implement countermeasures for this.


Can you please tell me how to make registry file or application settings?


Here is an excellent source for working with the registry. I have used this as a reference in the past, and it will cover everything you will need to know.

As for application settings, open the project designer (My Project) and click the Settings tab.

Create a new variable to store the date in and give it a value.

To access this while coding, do the following.

Dim date1 as Date = My.Settings.MyDate

For updating the date:

My.Settings.MyDate = Now.AddMonths(6)
My.Settings.Save() 'Critical to save or the changes will not be commited.

When using settings, the application settings are stored in an xml file in the application's directory. (Easy to access by user.)

This can be changed and can lead to dishonesty from the user.

Edited by Begginnerdev

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.