Ese código (incompleto) es muy
vb6 (como todo lo que sueles mostrar hasta ahora), sería mucho mejor que intentes hacerlo por ti mismo usando el estilo .NET, que usar códigos como ese.
Lo mejor es usar un programa que añada el sistema de expiración profesional, pero bueno, toma un ejemplo de una expiración muy sencilla:
' [Trial Expiration]
'
' By Elektro H@cker
#Region " Easy Trial Expiration "
Public Class TrialExpiration
#Region " Variables "
''' <summary>
''' The date that the expiration started.
''' </summary>
Public Property TrialDateStart As New Date(Nothing)
''' <summary>
''' The date that the expiration ends.
''' </summary>
Public Property TrialDateEnd As New Date(Nothing)
''' <summary>
''' Expiration days.
''' </summary>
Public Property TrialDays As Integer = 0
''' <summary>
''' Expiration days left.
''' </summary>
Public Property DaysLeft As Integer = 0
''' <summary>
''' Indicates wether the expiration has expired.
''' </summary>
Public Property IsExpired As Boolean = False
''' <summary>
''' Indicates the application compiled executable name to avoid the user renaming the file.
''' </summary>
Private EXEname As String = String.Empty
#End Region
#Region " Constructor "
''' <summary>
''' Creates a new Trial Expiration.
''' </summary>
''' <param name="EXEname">
''' The application compiled executable name.
''' This way if the compiled executable name is manipulated by the user, an expired case will be trhown.
''' </param>
''' <param name="TrialDays">
''' Amount of days to expire.
''' </param>
Public Sub New(ByVal EXEname As String, ByVal TrialDays As Integer)
EXEname = EXEname
Me.TrialDays = TrialDays
SetTrialDates()
GetDaysLeft()
End Sub
#End Region
#Region " Public Methods "
''' <summary>
''' Resets the Trial Expiration.
''' </summary>
Public Sub Reset()
My.Settings.TrialDate = String.Empty
My.Settings.Save()
' My.Settings.Reload()
End Sub
#End Region
#Region " Private Methods "
Private Sub SetTrialDates()
' If it's application first time run then set the initial date as Today.
If String.IsNullOrEmpty(My.Settings.TrialDate) Then
My.Settings.TrialDate = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(Today.ToString))
My.Settings.Save()
My.Settings.Reload()
End If
Try
TrialDateStart = Date.Parse(System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(My.Settings.TrialDate)))
Catch ex As FormatException
' Exception thrown if the user has corrupted the base64 string from the settings file.
' Then truncates the initial date to force trial expiration.
TrialDateStart = Date.Parse("0001/01/01")
End Try
TrialDateEnd = TrialDateStart.AddDays(Me.TrialDays)
End Sub
Private Sub GetDaysLeft()
Me.DaysLeft = (DateTime.Now.Subtract(Today) - DateTime.Now.Subtract(TrialDateEnd)).Days
Me.IsExpired = (Me.DaysLeft <= 0 _
OrElse Today < TrialDateStart _
OrElse Not String.Compare(Process.GetCurrentProcess().MainModule.ModuleName, EXEname, True) = 0)
' "OrElse Today < TrialDateStart" explanation:
' If the user has manipulated te Windows OS date.
' OrElse Process.GetCurrentProcess().MainModule.ModuleName <> EXEname
End Sub
#End Region
End Class
#End Region
Public Class Form1
Private WithEvents _Trial As New TrialExpiration("WindowsApplication1.exe", 7)
Private Shadows Sub Shown() Handles MyBase.Shown
' _Trial.Reset()
Select Case _Trial.IsExpired
Case True
MsgBox(String.Format("Your copy of this software has expired on {0}.",
_Trial.TrialDateEnd.ToString))
Case False
MsgBox(String.Format("You have {0} expiration remaining days.",
CStr(_Trial.DaysLeft)))
End Select
End Sub
End Class
Debes añadir una nueva setting llamada "
TrialDate" de tipo
String y de scope "
User".
Saludos.