Results 1 to 6 of 6

Thread: Trial Version in programming

  1. #1

    Thread Starter
    Addicted Member kobusjhg's Avatar
    Join Date
    Jul 2023
    Location
    Pretoria, South Africa
    Posts
    157

    Trial Version in programming

    Good day Everybody,

    I have developed a software application. This application has a trial version, which works fine, obviously not perfect, because the security built in serves my purpose. The problem I have is that when the user registers on the trial version, it emails me his pc info. When I get this info I have to create a license key, program it in a Full Version copy and send the user the link for the full version.

    Is there a way to change the trial copy to a full version copy once the user has registered?

    Kind Regards

    Kobus

  2. #2
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    874

    Re: Trial Version in programming

    I used a registry key for it, when I did that.
    I did not make it too complex of a scheme, but I did run it thru an xor encryption to store the info so no one could just read it and use it.

    Not fancy, not meant for strong security as people could share the key.

    Code:
    	Private Sub cmdActivate_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdActivate.Click
    		
    		Dim Regdemo As String
    		txtActivate.Text = Trim(txtActivate.Text)
    		If Trim(txtActivate.Text) = "WX772-K9EDF-32ESH-TE6Q6-W9MR6" Then
    			If frmlogonTypeOfOS = "Windows 2000" Then
    				Regdemo = Encrypt((txtActivate.Text), "1234567890")
    			Else
    				Regdemo = Encrypt((txtActivate.Text), "SDLS123")
    			End If
    			
    			' original code was "WX7R1-L9ODF-32ESA-TE6Q1-W9MR8"
    			SaveSetting(My.Application.Info.Title, "Fixture", "Type", Regdemo)
    			MsgBox("Product is activated.")
    			ToolTip1.SetToolTip(txtActivate, "")
    			frmlogondemotest = False
    		Else
    			MsgBox("Invalid code, product has not been activated.")
    			ToolTip1.SetToolTip(txtActivate, "Enter activation code here.")
    		End If
    		
    	End Sub
    Then in the main form, I used this pull the key info and determine if it matched

    Code:
      Dim Regdemo As String
      Regdemo = GetSetting(My.Application.Info.Title, "Fixture", "Type", "")
     
      If Regdemo = "" Then SaveSetting(My.Application.Info.Title, "Fixture", "Type", "False")
      frmlogonTypeOfOS = "Windows 2000"
      If frmlogonTypeOfOS = "Windows 2000" Then
          Regdemo = Encrypt(Regdemo, "1234567890")
      Else
          Regdemo = Encrypt(Regdemo, "SDLS123")
      End If
      '  Regdemo = Encrypttest(Regdemo, "1234567890")
    
      Regdemo = Trim(Regdemo)
      If Regdemo = "WX772-K9EDF-32ESH-TE6Q6-W9MR6" Then
          frmlogondemotest = False
      Else
          frmlogondemotest = True
      End If
    Last edited by sdowney1; Jul 14th, 2024 at 01:04 PM.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,671

    Re: Trial Version in programming

    Quote Originally Posted by kobusjhg View Post
    Good day Everybody,

    I have developed a software application. This application has a trial version, which works fine, obviously not perfect, because the security built in serves my purpose. The problem I have is that when the user registers on the trial version, it emails me his pc info. When I get this info I have to create a license key, program it in a Full Version copy and send the user the link for the full version.

    Is there a way to change the trial copy to a full version copy once the user has registered?

    Kind Regards

    Kobus
    In a nutshell, and keeping in mind that it also depends on how you disabled the "full" features to begin with. Presumably, the user would go somewhere in settiongs and "register" their install. You write something somewhere - a file, the registry, both, byte of the app... what ever... From that point on, you check that spot, if it has a valid key, then you trip a flag, that is then used to turn on the full features. if the key is wrong, or doesn't exist, then the flag remains off, and the features disabled...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Addicted Member kobusjhg's Avatar
    Join Date
    Jul 2023
    Location
    Pretoria, South Africa
    Posts
    157

    Re: Trial Version in programming

    Thank You Everybody, I am going to try it

    Kobus

  5. #5
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    874

    Re: Trial Version in programming

    I used this to encrypt a string a registry key

    You pass in a string 'secret', it returns an encrypted string

    Pass in an encrypted string, it decrypts the string.

    You can change the password.
    This still works in the windows registry today.

    Mabe it can give some ideas.

    Code:
        Public Function Encrypt(ByRef secret As String, ByRef PassWord As String) As String
            Dim yada As String
            Dim L As Short
    
            Dim char_Renamed As String
            Dim X As Short
    
            yada = frmlogonConnectstring
            '????
            'The passwords and privileges are encrypted with "1234567890"
            'the connection string is encrypted with "123456789"
            'Win98 had a problem with 1234567890
    
            ' secret = the string you wish to encrypt or decrypt.
            ' PassWord = the password with which to encrypt the string.
            On Error GoTo errhandler
            ' priv = Encrypt("A11111111111111111111", "1234567890")
    
            '' secret = "A11111111111111111111"
            ''  PassWord = "1234567890"
    
            L = Len(PassWord)
            For X = 1 To Len(secret)
                char_Renamed = CStr(Asc(Mid(PassWord, (X Mod L) - L * CShort((X Mod L) = 0), 1)))
                Mid(secret, X, 1) = Chr(Asc(Mid(secret, X, 1)) Xor char_Renamed)
            Next
    
            Encrypt = secret
            frmlogonConnectstring = yada
            Exit Function
    
    errhandler:
    
            Err.Clear()
            On Error GoTo errhandler2
    
            'like chinese unicode???
    
            L = Len(PassWord)
            For X = 1 To Len(secret)
                char_Renamed = CStr(AscW(Mid(PassWord, (X Mod L) - L * CShort((X Mod L) = 0), 1)))
                Mid(secret, X, 1) = ChrW(AscW(Mid(secret, X, 1)) Xor char_Renamed)
            Next
    
            Encrypt = secret
            frmlogonConnectstring = yada
            Exit Function
    errhandler2:
    
            Encrypt = secret
            frmlogonConnectstring = yada
        End Function

  6. #6

    Thread Starter
    Addicted Member kobusjhg's Avatar
    Join Date
    Jul 2023
    Location
    Pretoria, South Africa
    Posts
    157

    Re: Trial Version in programming

    Thank you people,
    I did manage to get it right.
    Main Form Code
    Code:
    Imports Microsoft.Win32
    Imports System.Net.NetworkInformation
    
    Public Class frmMain
        Private Sub lblLinkLabelStartProgram_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lblLinkLabelStartProgram.LinkClicked
            Form1.Show()
        End Sub
    
        Private Sub lblLinkLabelRegisterSoftware_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lblLinkLabelRegister.LinkClicked
            ' Show the registration form
            Dim registrationForm As New Registration()
            registrationForm.ShowDialog()
        End Sub
    
        Private Sub lblLinkLabelQuitProgram_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lblLinkLabelQuit.LinkClicked
            ' Close the application
            Application.Exit()
        End Sub
    
        Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                Dim deviceId As String = GetDeviceId()
                Dim registryKey As RegistryKey = Registry.CurrentUser.CreateSubKey($"Software\SoftwareApp\{deviceId}")
    
                If registryKey IsNot Nothing Then
                    ' Check if the software is registered
                    Dim isRegistered As String = TryCast(registryKey.GetValue("IsRegistered"), String)
                    If isRegistered = "True" Then
                        MessageBox.Show("Full Version Active!")
                        registryKey.Close()
                        Return
                    ElseIf isRegistered = "Pending" Then
                        ' Prompt for registration code
                        PromptForRegistrationCode()
                        registryKey.Close()
                        Return
                    End If
    
                    ' Check if the timestamp exists in the Registry
                    Dim storedTimestamp As String = TryCast(registryKey.GetValue("TrialTimestamp"), String)
                    If String.IsNullOrEmpty(storedTimestamp) Then
                        ' First run for this device, store the current timestamp
                        registryKey.SetValue("TrialTimestamp", DateTime.Now.ToString())
                        MessageBox.Show("First Run for this device...")
                    Else
                        ' Convert the stored timestamp back to DateTime
                        Dim storedDateTime As DateTime = DateTime.Parse(storedTimestamp)
                        ' Calculate the remaining days of the trial
                        Dim remainingDays As Integer = CInt((storedDateTime.AddDays(30) - DateTime.Now).TotalDays)
                        If remainingDays > 0 AndAlso remainingDays <= 30 Then
                            MessageBox.Show($"Trial Active! {remainingDays} days left.")
                        Else
                            MessageBox.Show("Trial Expired!")
                            ' Prompt for registration code
                            PromptForRegistrationCode()
                        End If
                    End If
    
                    ' Close the RegistryKey when done
                    registryKey.Close()
                End If
            Catch ex As Exception
                MessageBox.Show($"Error: {ex.Message}")
            End Try
        End Sub
    
        Private Sub PromptForRegistrationCode()
            Dim registrationCode As String = InputBox("Enter your registration code:", "Register Software")
    
            If Not String.IsNullOrEmpty(registrationCode) Then
                ' Validate registration code
                If ValidateRegistrationCode(registrationCode) Then
                    MessageBox.Show("Registration successful!")
                    ' Mark the software as registered and save the code
                    Dim deviceId As String = GetDeviceId()
                    Dim registryKey As RegistryKey = Registry.CurrentUser.CreateSubKey($"Software\SoftwareApp\{deviceId}")
                    If registryKey IsNot Nothing Then
                        registryKey.SetValue("IsRegistered", "True")
                        registryKey.SetValue("RegistrationCode", registrationCode)
                        registryKey.Close()
                        MessageBox.Show("Registry updated successfully!")
                    End If
                Else
                    MessageBox.Show("Invalid registration code. Please try again.")
                End If
            End If
        End Sub
    
        Private Function ValidateRegistrationCode(code As String) As Boolean
            Dim deviceId As String = GetDeviceId()
            Dim registryKey As RegistryKey = Registry.CurrentUser.OpenSubKey($"Software\SoftwareApp\{deviceId}")
            If registryKey IsNot Nothing Then
                Dim expectedCode As String = TryCast(registryKey.GetValue("ExpectedRegistrationCode"), String)
                registryKey.Close()
                Return code = expectedCode
            Else
                Return False
            End If
        End Function
    
        Private Function GetDeviceId() As String
            ' Generate a unique identifier for the device using MAC address
            Dim networkInterface As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault()
            If networkInterface IsNot Nothing Then
                Return BitConverter.ToString(networkInterface.GetPhysicalAddress().GetAddressBytes())
            Else
                Return "UnknownDevice"
            End If
        End Function
    End Class

    Registration Code
    Code:
    Imports Microsoft.Win32
    Imports System.Net.NetworkInformation
    Imports System.Net.Mail
    Imports System.IO
    
    Public Class Registration
        Private Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
            Dim userFirstName As String = txtFirstName.Text
            Dim userSurname As String = txtSurname.Text
            Dim userCompanyName As String = txtCompanyName.Text
            Dim userEmail As String = txtEmailAddress.Text
            Dim userDate As String = txtDate.Text
    
            Dim userDeviceId As String = GetDeviceId()
            Dim registrationCode As String = GenerateRegistrationCode()
    
            Dim registrationInfo As String = $"Device ID: {userDeviceId}" & Environment.NewLine &
                                             $"Registration Code: {registrationCode}" & Environment.NewLine &
                                             $"First Name: {userFirstName}" & Environment.NewLine &
                                             $"Surname: {userSurname}" & Environment.NewLine &
                                             $"Company Name: {userCompanyName}" & Environment.NewLine &
                                             $"Email: {userEmail}" & Environment.NewLine &
                                             $"Date: {userDate}" & Environment.NewLine &
                                             "------------------------------------------" & Environment.NewLine
    
            ' Send email (you need to configure the SMTP client with your settings)
            Try
                Dim smtpClient As New SmtpClient("smtp.gmail.com")
                smtpClient.Port = 587
                smtpClient.Credentials = New Net.NetworkCredential("kobusjhg@gmail.com", "fnkf bwuw azuq pybu")
                smtpClient.EnableSsl = True
    
                Dim mailMessage As New MailMessage()
                mailMessage.From = New MailAddress("kobusjhg@gmail.com")
                mailMessage.To.Add("kobusjhg@gmail.com") ' Administrator's email
                mailMessage.Subject = "Registration Information"
                mailMessage.Body = registrationInfo
    
                smtpClient.Send(mailMessage)
    
                ' Mark as registered and prompt for the code on the next run
                Dim registryKey As RegistryKey = Registry.CurrentUser.CreateSubKey($"Software\SoftwareApp\{userDeviceId}")
                registryKey.SetValue("IsRegistered", "Pending")
                registryKey.SetValue("ExpectedRegistrationCode", registrationCode)
                registryKey.Close()
    
                ' Write registration info to text file
                Dim directoryPath As String = "D:\Programs\Database\Programs\Symbolic Signs"
                Dim filePath As String = Path.Combine(directoryPath, "RegistrationInfo.txt")
    
                ' Ensure the directory exists
                If Not Directory.Exists(directoryPath) Then
                    Directory.CreateDirectory(directoryPath)
                End If
    
                ' Append registration info to the file
                File.AppendAllText(filePath, registrationInfo)
    
                MessageBox.Show("Registration information sent and saved. Please restart the application after you receive the registration code via email.")
                Me.Close()
            Catch ex As Exception
                MessageBox.Show($"Error sending email: {ex.Message}")
            End Try
        End Sub
    
        Private Function GetDeviceId() As String
            ' Generate a unique identifier for the device using MAC address
            Dim networkInterface As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault()
            If networkInterface IsNot Nothing Then
                Return BitConverter.ToString(networkInterface.GetPhysicalAddress().GetAddressBytes())
            Else
                Return "UnknownDevice"
            End If
        End Function
    
        Private Function GenerateRegistrationCode() As String
            ' Generate a random alphanumeric registration code
            Dim chars As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
            Dim code As New Text.StringBuilder()
            Dim rnd As New Random()
    
            For i As Integer = 1 To 5
                code.Append(chars(rnd.Next(chars.Length)))
            Next
            code.Append("-")
            For i As Integer = 1 To 5
                code.Append(chars(rnd.Next(chars.Length)))
            Next
            code.Append("-")
            For i As Integer = 1 To 5
                code.Append(chars(rnd.Next(chars.Length)))
            Next
    
            Return code.ToString()
        End Function
    
        Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
            Me.Close()
        End Sub
    
        Private Sub lblLinkLabelBankDetails_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lblLinkLabelBankDetails.LinkClicked
            BankDetails.Show()
        End Sub
    End Class
    What this code does: -
    1) It installs the trial version using the MAC no in order for it to be used only on one device.
    2) The trial version is valid for 30 days.
    3) The registry is updated as well
    4) On the trial version is a Register link where the user puts in information.
    5) This info is sent to me by email and also creates a file on my PC. This file is where all users registration info and registration keys are kept.
    6) I email the registration keys after registration.
    7) The software will ask for the code and as soon as the code is put in, it changes it to a full version.

    So far it is working fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width