Thursday, 18 April 2013

Check Application Expiry Date

                               Check And Set Expiry Date For Application

Every client asking for assigning expiry date for his application because of security policy and
protection scheme,programmer have different way to do this.
        1.Use a two-way hash to store the initial date and compare that to the present date. 
           You can save the hash to disk.
        2.Use the registry key of current user and set the key value at installation time and compare
           to change the value in particular Date. 
        3.Use the created date of your installation files as a reference.
        4.Create a license key that encodes the expiry date into the key and read this when the
           application runs.

Well here i write a small code for checking expire date to the application,with the help of Date and
Registry feature- 
Imports Microsoft.Win32
Imports System.IO.Directory
Imports Microsoft.VisualBasic.DateAndTime
Public Class ThisWorkbook

    Private Function checkExpired()
        Dim RS232RegKey As RegistryKey
        Dim pluginExpired As Boolean = False
         If Year(Now) > 2013 Or Year(Now) < 2013 Then
             pluginExpired = True
         End If
         If Month(Now) > 4 Or Month(Now) < 4 Then
             pluginExpired = True
         End If
        If Day(Now) > 16 Or Day(Now) < 13 Then
             pluginExpired = True
         End If

        RS232RegKey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Office\Excel\Addins\RS232")
        RS232RegKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Office\Excel\Addins\RS232", True)

         If RS232RegKey.GetValue("PluginExpired") Is Nothing Then
             RS232RegKey.SetValue("PluginExpired", 1, RegistryValueKind.DWord)
         End If
         If pluginExpired = True Then
             RS232RegKey.SetValue("PluginExpired", 0, RegistryValueKind.DWord)
         End If

        Dim PluginExpiredRegVal As Integer = RS232RegKey.GetValue("PluginExpired")
        RS232RegKey.Close()

         If pluginExpired = True Or PluginExpiredRegVal = 0 Then
             MsgBox("Plugin Expired")
             Return True
         End If
         Return False
    End Function

    Private Sub ThisWorkbook_Startup() Handles Me.Startup
        Globals.Sheet2.ButtonStop.Enabled = False
        If (checkExpired()) Then
            Globals.ThisWorkbook.Save()
            Globals.ThisWorkbook.Close()
        End If
    End Sub    

End Class

No comments:

Post a Comment