Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I Use an Expire date code in Windows Applications, and The application must close after the expire date and the application does not work even though when the user changes system date to previous date. Please anyone help me out of this problem.

I used this vb.net code for my Windows Application, but if I change the system date then application will run.

[CODE]

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim dateFile As String = "\Data.txt"
Dim filePath As String = My.Computer.FileSystem.SpecialDirectories.Programs
Dim fullPathAndFilename As String = filePath & dateFile

Dim dateFromFile As Date
Dim ts As TimeSpan


If System.IO.File.Exists(fullPathAndFilename) = True Then

Using sr As New System.IO.StreamReader(fullPathAndFilename)

Date.TryParse(sr.ReadLine, dateFromFile)

ts = Now.Subtract(dateFromFile)

If ts.TotalDays > 1 Then
Dim result As DialogResult = MessageBox.Show("Software trial expired, sorry.")
If result = Windows.Forms.DialogResult.OK Or result = Windows.Forms.DialogResult.Cancel Then
sr.Close()
End
End If
Else

End If
sr.Close()
End Using

ElseIf System.IO.File.Exists(fullPathAndFilename) = False Then
Using sw As New System.IO.StreamWriter(fullPathAndFilename)
sw.WriteLine(Now.ToLongDateString & " " & Now.ToLongTimeString)
sw.Close()
End Using
End If

End Sub
[/CODE]

Thanks and Regards
BASVA.
Posted
Updated 17-Oct-14 22:43pm

1 solution

There is no real way to be completely secure from this problem, except to use an external date and time service (such as your own website) to verify that an application is still within it's expiration period.

But you can help by recording the date and time of the last use in a config file somewhere and checking that when you start - if you are earlier than the "last use" value then something is amiss! But be careful: firstly that seasonal clock changes don't affect you, and that the user can legitimately correct his system clock without being told he is a thief! (My system for example corrects itself to an internet time service at intervals so it is always pretty much correct).

Nothing will annoy legitimate customers more than not being able to use the software they have paid for because your checking gets a false positive! :laugh:
 
Share this answer
 
Comments
Member 11140188 18-Oct-14 7:01am    
Thanks for the Information Shared.:)
OriginalGriff 18-Oct-14 7:11am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900