Thread: [VB.Net] How To Create A "Trial Version" To Implement To Your Application!

Results 1 to 9 of 9
  1. #1 [VB.Net] How To Create A "Trial Version" To Implement To Your Application! 
    Can I Be Vet Pls?

    Trytohaxme's Avatar
    Join Date
    May 2008
    Age
    31
    Posts
    2,401
    Thanks given
    1
    Thanks received
    21
    Rep Power
    1478
    Steps to create DLL:

    1) Start Visual Studio 2005, Create New Project select Class Library Name it “MyTrialVersionApp”.

    2) Write The Following Code In it.

    Code:
    Imports Microsoft.Win32
    Public Class RegistryTrial
        Private Last, First, RemainsDays, RemainsDays1, strOldDay, strOldMonth, strOldYear As String
        'Number of Days Of the trial version.
        Private mintSystem_UsedTrialDays As Integer 'Number of days system used
        Public StartDate As String 
        Public LastDate As String 
        Public FinalDate, FinalDateTime As String
        Public Function Regedit(ByVal TrialPeriod As Integer) As String
      'It first create Key then Stored value in it 
      Dim regKey As RegistryKey
      Try
        Dim strRet As String = ""
        regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
        regKey = Registry.LocalMachine.OpenSubKey("Software\AppSecurity", True)
        If regKey Is Nothing Then
        regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
        regKey.CreateSubKey("AppSecurity")
        regKey.Close()
        If WriteValue(TrialPeriod) = False Then
        Return "setting fail."
        End If
        Else
        strRet = GetValueFromReg(TrialPeriod)
        Return strRet
        End If
      Catch ex As Exception
        Return ""
      End Try
        End Function
    
        Public Function GetValueFromReg(ByVal mintTrialPeriod As Integer) As String
      'This Function is used to Get/Read The Value from the registry
      Dim strReturn As String = ""
      Dim regKey As RegistryKey
      Dim ver, Final As String
      regKey = Registry.LocalMachine.OpenSubKey("Software\AppSecurity", True) 'its opens the path to read value
      ver = regKey.GetValue("System_In") 'System_In=It get the value in (StartDate) & ";" & (LastDate) which is already stored in Encrypted formate.
    
      If ver = "" Then 'If User Change It
        Return "You have change some module,you are un-authorised to use the application."
      Else
        Final = funcDecrpt_Date(ver) 'this Decrypt the Value
        If Final.Length() = "21" Then
        Last = Final.Substring(11)
        strOldDay = Final.Substring(0, 2) 'It Display Day ex:"01"
        strOldMonth = Final.Substring(3, 2) 'It Display Month ex:"01"
        strOldYear = Final.Substring(6, 4) 'It Display Year ex:"2009"
        First = Final.Substring(0, 10) 'It Display startdate from Registry
    
        RemainsDays = DisplayApplicationStatus(DiffDate(strOldDay, strOldMonth, strOldYear), mintTrialPeriod)
        mintSystem_UsedTrialDays = DiffDate(strOldDay, strOldMonth, strOldYear)
        Dim todaydate As String
        todaydate = Format(Today, "dd/MM/yyyy")
        'it Comapairs the LastDate Stored in Registry with Todaysdate
        If RemainsDays1 = 0 Then
        Return "Sorry,Your trial period is over!!Please purchase this software."
        Else
        Dim LastMonth As String
        Dim CurrentMonth As String
        LastMonth = Last.Substring(3, 2)
        CurrentMonth = todaydate.Substring(3, 2)
        If LastMonth > CurrentMonth Then
        If Last = todaydate Or First > todaydate Then
        Return "Sorry,Your trial period is over!!Please purchase this software."
    
        Else
        strReturn = GetLastAccessDateTime()
        If strReturn <> "LogIn" Then
        Return strReturn
        Else
        If RemainsDays1 = Nothing Then
        Return "123Today is your last day in your free trial period."
        Else
        Return "123You have " & RemainsDays1 & " days remaining in your free trial period."
        End If
        End If
        End If
        Else
        If Last = todaydate Or Last < todaydate Or First > todaydate Then
        Return "Sorry,Your trial period is over!!Please purchase this software."
        Else
        strReturn = GetLastAccessDateTime()
        If strReturn <> "LogIn" Then
        Return strReturn
        Else
        If RemainsDays1 = Nothing Then
        Return "123Today is your last day in your free trial period."
        Else
        Return "123You have " & RemainsDays1 & " days remaining in your free trial period."
        End If
        End If
        End If
        End If
        End If
        Else
        Return "You have change some module,you are un-authorised to use the application."
        End If
      End If
        End Function
    
        Public Function funcEncrpt_Date(ByVal mDate As String) As String
      'This function used to stored dates in the Encrypted Formate in the Registry
      Dim intI As Integer = 0
      Dim mstrDate As String = ""
      Try
        For intI = 1 To Len(mDate)
        If Mid(Trim(mDate), intI, 1) = "1" Then
        mstrDate = mstrDate & ChrW(Asc(Mid(Trim(mDate), intI, 1)) - 5)
        Else
        mstrDate = mstrDate & ChrW(Asc(Mid(Trim(mDate), intI, 1)) - 10)
        End If
        Next
        If InStr(mstrDate, "'") <> 0 Then
        mstrDate = mstrDate & "'"
        End If
      Catch ex As Exception
      End Try
      Return mstrDate
        End Function
    
        Public Function funcDecrpt_Date(ByVal mDate As String) As String
      'This Decrypts the dates which is stored in the registry in Encrypted Formate and used in the application
      Dim intI As Integer = 0
      Dim mstrDate As String = ""
      Try
        For intI = 1 To Len(mDate)
        If Mid(Trim(mDate), intI, 1) = "," Then
        mstrDate = mstrDate & ChrW(Asc(Mid(Trim(mDate), intI, 1)) + 5)
        Else
        mstrDate = mstrDate & ChrW(Asc(Mid(Trim(mDate), intI, 1)) + 10)
        End If
        Next
      Catch ex As Exception
      End Try
      Return mstrDate
        End Function
    
        Public Function WriteValue(ByVal TrialPeriod As Integer) As Boolean
      'This Function Writes The value in thw registry
      Dim regKey As RegistryKey
      Dim SaveFirstAccessdate As String
      Try
        regKey = Registry.LocalMachine.OpenSubKey("Software\AppSecurity", True)
        StartDate = Format(Today, "dd/MM/yyyy")
        LastDate = Format(Today.AddDays(TrialPeriod), "dd/MM/yyyy")
        FinalDate = funcEncrpt_Date(StartDate) & ";" & funcEncrpt_Date(LastDate)
        regKey.SetValue("System_In", FinalDate) 'This write StartDate and Lastdate In the Registry
        SaveFirstAccessdate = Format(Today, "dd/MM/yyyy") & ";" & Format(TimeOfDay, "hh:mm:ss tt")
        regKey.SetValue("System_Used", funcEncrpt_Date(SaveFirstAccessdate)) 'This write Last used system DATE;TIME In the Registry
        regKey.SetValue("AppName", "AppSecurity") 'This write Application Name in Registry 
        regKey.Close()
        Return True
      Catch ex As Exception
        Return False
      End Try
        End Function
        Public Function GetLastAccessDateTime() As String
      'This function is used to get value from registry (Last used DateTime)
      Try
        Dim regKey As RegistryKey
        regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
        Dim LastAccess As String
        regKey = Registry.LocalMachine.OpenSubKey("Software\AppSecurity", True)
        LastAccess = regKey.GetValue("System_Used") ', funcDecrpt_Date(FinalDateTime))
        If LastAccess = "" Or LastAccess.Length <> "22" Then
        Return "You have change some module,you are un-authorised to use the application."
        Else
        Dim TodayDate As String
        TodayDate = (Format(Today, "dd/MM/yyyy") & ";" & Format(TimeOfDay, "hh:mm:ss tt"))
        If TodayDate < funcDecrpt_Date(LastAccess) Then
        Return "You have change your system Date mannually,you are un-authorised to use the application."
        Else
        Return "LogIn"
        End If
        End If
        regKey.Close()
      Catch ex As Exception
        Return ""
      End Try
        End Function
        Public Sub SaveLastAceessDateTime()
      'this function used on the form exit ,to save Last Used System DateTime
      Try
        Dim regKey As RegistryKey
        regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
        Dim SaveLastAccessdate As String
        regKey = Registry.LocalMachine.OpenSubKey("Software\AppSecurity", True)
        SaveLastAccessdate = Format(Today, "dd/MM/yyyy") & ";" & Format(TimeOfDay, "hh:mm:ss tt")
        FinalDateTime = funcEncrpt_Date(SaveLastAccessdate)
        regKey.SetValue("System_Used", FinalDateTime)
        regKey.Close()
      Catch ex As Exception
    
      End Try
        End Sub
    
        Public Function DisplayApplicationStatus(ByVal pDaysSystem_Used As Integer, ByVal pTotalDays As Integer) As String
      'Check if the author made the mistake of setting the trial period days to less than 0
      If pTotalDays < 0 Then
        Return "An error has occurred! The author has alloted you a trial period less than zero days, which is impossible. Please contact the author and tell him/her of this error."
      End If
    
      'Check if the trial is expired
      If pDaysSystem_Used >= pTotalDays Then
        Return "Your trial has expired!"
      End If
    
      'Draw the bar
      RemainsDays1 = pTotalDays - pDaysSystem_Used
      Return "You have " + (pTotalDays - pDaysSystem_Used).ToString + " days remaining in your free trial period."
        End Function
    
        Public Function DiffDate(ByVal OrigDay As String, ByVal OrigMonth As String, ByVal OrigYear As String) As Integer
      Try
        Dim D1 As Date = New Date(Convert.ToInt32(OrigYear), Convert.ToInt32(OrigMonth), Convert.ToInt32(OrigDay))
        Return Convert.ToInt32(DateDiff(DateInterval.Day, D1, DateTime.Now))
      Catch
        Return 0
      End Try
        End Function
    End Class
    3) After writing this code in the Class Library Application Save it And Run it.

    4) The DLL get created in the Bin Folder Of your Application.

    5) Copy it and Paste In your another application where you want to use it(i.e. 10 days trial version application you want to make)

    6) Open your another project click on Project Add reference



    7) Browse your DLL Path and select it



    8) Then click ‘Ok’ button, it will get added to your project.

    9) Write the Following Code on this application

    Write it on form Load Event:
    Code:
      Dim obj As New Trial_Version.RegistryTrial
      'The following code is used to operate Trial Version DLL 
      Dim str As String = obj.Regedit(10) 'no of trial days
    
      If str = Nothing Then
        Me.Close()
      Else
        If str.StartsWith("123") = True Then
        MsgBox(str.Substring(3), MsgBoxStyle.Information, "Information")
        If Me.MdiChildren.Length > 0 Then
        Exit Sub
        End If
        Dim frm As New Login
        If frm.IsMdiChild = True Then
        frm.Focus()
        Else
        frm.Dispose()
        frm = New Login
        frm.MdiParent = Me
        Me.MenuStrip.Enabled = False
        frm.Show()
        End If
        Else
        MsgBox(str, MsgBoxStyle.Critical, "Error")
        Me.Close()
        End If
      End If
    Write following on close Button:
    Code:
      If MessageBox.Show("Are you sure,you want to Exit application.", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
        Dim obj As New Trial_Version.RegistryTrial
        obj.SaveLastAceessDateTime()
        Me.Close()
      Else
        Me.Show()
      End If
    10) To See your registry :

    Click on Strart RUN and Type regEdit and press OK Buton…

    Select (HKEY_LOCAL_MACHINE - SOFTWARE - AppSecurity)
    Attached image
     

  2. #2  
    Pro Coder Donator <3 Valderg's Avatar
    Join Date
    Jul 2010
    Posts
    40
    Thanks given
    2
    Thanks received
    0
    Rep Power
    9
    First, FUCKING SEXY
    Spoiler for FUCKING LOL.:




    Spoiler for Trusted By:

    Code:
    Chocothunda, Eesti11, rs4easy


    Fuck you Jeff
     

  3. #3  
    Registered Member
    Join Date
    Nov 2009
    Posts
    31
    Thanks given
    1
    Thanks received
    3
    Rep Power
    0
    first
    from
    volume
    /
    united
    of
    runelife
     

  4. #4  
    Registered Member
    Mister Maggot's Avatar
    Join Date
    Dec 2008
    Posts
    7,227
    Thanks given
    3,283
    Thanks received
    2,875
    Rep Power
    5000
    Using the registry for trial products is terrible.
     

  5. Thankful user:


  6. #5  
    Registered Member

    Join Date
    Oct 2009
    Posts
    149
    Thanks given
    4
    Thanks received
    20
    Rep Power
    97
    Quote Originally Posted by Mister Maggot View Post
    Using the registry for trial products is terrible.
    I agree, the only true way to make a trial product is to either shorten the entire product to have less features(100% safe), or have it require authorization from a server(Safety depends on various things).
     

  7. #6  
    Client Developer

    Pb600's Avatar
    Join Date
    Dec 2008
    Posts
    2,153
    Thanks given
    259
    Thanks received
    472
    Rep Power
    925
    Quote Originally Posted by Mister Maggot View Post
    Using the registry for trial products is terrible.
    Don`t even see how Java Rabel does to make their trial
    Attached image
     

  8. #7  
    Registered Member
    Mister Maggot's Avatar
    Join Date
    Dec 2008
    Posts
    7,227
    Thanks given
    3,283
    Thanks received
    2,875
    Rep Power
    5000
    Quote Originally Posted by Pb600 View Post
    Don`t even see how Java Rabel does to make their trial
    Please clarify your post; idk whatcha mean.
     

  9. #8  
    Registered Member
    Join Date
    Mar 2012
    Posts
    1
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    First of all, Amazing job

    man, this helps me a lot

    but, What if I need to build an Activation Window or registration form

    so the end user can add some sort of serial number and makes the software works as a Full Version

    Thanks in advance

    Best Regards
     

  10. #9  
    Registered Member Nouish's Avatar
    Join Date
    Jun 2011
    Posts
    822
    Thanks given
    142
    Thanks received
    177
    Rep Power
    282
    Quote Originally Posted by moiyd View Post
    First of all, Amazing job

    man, this helps me a lot

    but, What if I need to build an Activation Window or registration form

    so the end user can add some sort of serial number and makes the software works as a Full Version

    Thanks in advance

    Best Regards
    With this, you will be able to edit the registry to have the full version ...
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. 48hr xbl trial anyone?
    By Omer5454 in forum Console
    Replies: 3
    Last Post: 12-12-2009, 06:43 AM
  2. 48 xbl trial
    By Songoty in forum Console
    Replies: 2
    Last Post: 12-11-2009, 09:28 AM
  3. WOW - Free Trial
    By Ryequis in forum PC
    Replies: 10
    Last Post: 03-02-2009, 12:36 AM
  4. how to implement
    By Dei Esercito in forum Application Development
    Replies: 5
    Last Post: 02-10-2009, 01:55 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •