This is for the people who like to know how to develop a trial period expiry code in vb.net .
those who have the basic knowledge of vb.net can easily understand the coding
above is the snapshot how the front end looks like the coding is simple and easy to understand. Add a class using project->Add window form->class.vb and rename the class as RegCheck:
Paste the following code
Imports Microsoft.Win32
Imports System.DBNull
Public Class RegCheck
Public ReadOnly Property HKeyLocalMachine() As RegistryKey
Get
Return Registry.LocalMachine
End Get
End Property
Public Function SubKey_Create(ByVal ParentKey As RegistryKey, _
ByVal SubKey As String) As Boolean
Dim Key As RegistryKey
Try
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then
Key = ParentKey.CreateSubKey(SubKey)
End If
Return True
Catch e As Exception
Return False
End Try
End Function
Public Function ReadValue(ByVal ParentKey As RegistryKey, _
ByVal SubKey As String, _
ByVal ValueName As String) As String
Dim Key As RegistryKey
Dim Value As String
Try
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then
Value = -1
Return Value
End If
Value = Key.GetValue(ValueName)
Return Value
Catch e As Exception
Return -1
End Try
End Function
Public Function ReadDate(ByVal ParentKey As RegistryKey, _
ByVal SubKey As String, _
ByVal ValueName As String) As String
Dim Key As RegistryKey
Dim Value As String
Value = "01/01/0001"
Try
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then
Value = "01/01/0001"
Return Value
End If
Value = Key.GetValue(ValueName)
If Value = "" Then
Value = "01/01/0001"
Return Value
Else
Return Value
End If
Catch e As Exception
Return "01/01/0001"
End Try
End Function
Public Function Compare_date(ByVal nvalue As String) As Integer
Dim tsTimeSpan As TimeSpan
Dim iNumberOfDays As Integer
tsTimeSpan = Now.Subtract(nvalue)
iNumberOfDays = tsTimeSpan.Days
Return iNumberOfDays
End Function
Public Function WriteValue(ByVal ParentKey As RegistryKey, _
ByVal SubKey As String, _
ByVal ValueName As String, _
ByVal Value As Object) As Boolean
Dim Key As RegistryKey
Try
'Open the given subkey
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then 'when subkey doesn't exist create it
Key = ParentKey.CreateSubKey(SubKey)
End If
'Once we have a handle to the key, set the value(the data)
Key.SetValue(ValueName, Value)
Return True
Catch e As Exception
Return False
End Try
End Function
End Class
next add a window form and name it as form1 and paste the folloeing code in the code area
Imports System.Windows.Forms
Public Class Form1
Dim s As New RegCheck
Dim total_days As String
Dim count As Integer
' Form Load Area Coding
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim days As String
'Dim total_days As String
Dim dte As Date
Dim nvalue As String
Dim licen As String
'Dim value As Date
Dim dat As String
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 30
count = 30
dte = Now.Date
dat = dte.ToString()
s.SubKey_Create(s.HKeyLocalMachine, "Software\CyberSoft\keys")
licen = s.ReadValue(s.HKeyLocalMachine, "Software\CyberSoft\keys", "license")
nvalue = s.ReadDate(s.HKeyLocalMachine, "Software\CyberSoft\keys", "strd")
If licen = 0 Then
If nvalue = "01/01/0001" Then
s.WriteValue(s.HKeyLocalMachine, "Software\CyberSoft\keys", "strd", dte)
s.WriteValue(s.HKeyLocalMachine, "Software\CyberSoft\keys", "no_of_days", "0")
s.WriteValue(s.HKeyLocalMachine, "Software\CyberSoft\keys", "license", "0")
Label1.Text = "30 days trail period left"
ProgressBar1.Value = 30
count = 30
Else
If DateTime.Compare(nvalue, dat) > 0 Then
s.WriteValue(s.HKeyLocalMachine, "Software\CyberSoft\keys", "strd", dat)
End If
total_days = s.Compare_date(nvalue)
days = s.ReadValue(s.HKeyLocalMachine, "Software\CyberSoft\keys", "no_of_days")
Dim tdays As Int32
Dim dys As Int32
tdays = Convert.ToInt32(total_days)
dys = Convert.ToInt32(days)
If dys < total_days =" s.ReadValue(s.HKeyLocalMachine," total_days =" 30" value =" 0" value =" total_days" count =" total_days" text =" total_days" text = "Trial period has been expired" value =" 0">' In Use Evaluation Version button
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If count <= 0 Then MessageBox.Show("Your trail period has been expired, Kindly buy the Liciense Key", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning) Else Dim main As New Form3 main.Show() Me.Hide() End If End Sub ' In the Buy Serial key button's code area
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Diagnostics.Process.Start(http://www.sourcecode-lancy.blogspot.com/)
End Sub
'In the Enter Licence Key buton's code area
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ad As New Form2
ad.Show()
Me.Close()
End Sub
End Class
you can store the license key in license registry key
1.Add a form
2.Add Textbox and Button control
3.In the coding area of button click check wheather the user inserted key in the textbox matches with the key you like, if the user has entered the correct key than store it in Registry Key license (this key is added in the form1 ) next the when you run the application form1 doesnt appear
if you have any doubts than u can mail me at lancy98@gmail.com
thank you
hay đấy !
ReplyDelete