How to make desktop application trial version for 30 day on csharp ?

ahmed salah 3,216 Reputation points
2021-02-13T01:37:03.927+00:00

I work on desktop application windows form by csharp language
I have issue I can't make it as trial for 30 day on customer pc
so How to do it trial version

I need to implement this logic algorithm but can't implement it

so How to do that please

suggest doing the following (during the first run of the application):

1. Create a registry entry to store an encrypted value of the expiration date (which can be calculated as n days from the installation date).

2. Create a hidden entry somewhere else (another place in the registry, a file stored in the Windows system folder, etc...) that indicates that step 1 was successfully completed. This is to allow the software to immediately stop functioning in case the user identifies and clears the registry entry created in 1.

3. Create another registry entry to store an encrypted value of the last date/time on which the software was run.

Now whenever the application is run (including the first time), you should:

1. Check for the registry entries 1, 2 and 3 above:

If 1 and 3 exist then
    If they are correctly encrypted (unmodified) then
        If the expiration date has not been reached AND the last-run date is older than the current date then
            Run the application
            Modify entry 3 to hold the current date (encrypted)
        Else if the last-run data is newer than the current date then
            Somebody has tried to change system clock. Catch! :-)
        Else
            The software has expired!
    Else
          Somebody tried to modify the encrypted values. Catch!
Else
    If hidden entry 2 exists
        Somebody cleared the entries 1 and 3. Catch!
    Else
        This is the first run! Create entries 1, 2 and 3
End if

_______________

can you please help me implementing logic above please by coding here
if possible help me

Developer technologies Windows Forms
Developer technologies C#
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-02-13T03:59:07.41+00:00

    Creating a trial versioning for an application is best done using professional installers such as this one (I have no ties to this company), next thought is to find someone who has developed this already such as this one while the least favorable is writing your own.

    • The problem using someone else's code is it takes time to understand the code while understanding hackers. Then eval'ing what are the chance of a hacker unlocking my app and will revenue be lost?
    • Then there is the thing about paid for installers, they are never cheap yet one needs to consider if an installer cost say $500 and I plan on decent revenue all is good while this is not a good choice if one is unsure of the revenue said software will generate.

    So weigh in the pro's and con's with purchase installer or code that can be downloaded.


  2. ahmed salah 3,216 Reputation points
    2021-02-13T23:02:13.06+00:00

    I need to implement this algorithm please

    1. Create a registry entry to store an encrypted value of the expiration date (which can be calculated as n days from the installation date).
    
     2. Create a hidden entry somewhere else (another place in the registry, a file stored in the Windows system folder, etc...) that indicates that step 1 was successfully completed. This is to allow the software to immediately stop functioning in case the user identifies and clears the registry entry created in 1.
    
     3. Create another registry entry to store an encrypted value of the last date/time on which the software was run.
    
     Now whenever the application is run (including the first time), you should:
    
     1. Check for the registry entries 1, 2 and 3 above:
    
     If 1 and 3 exist then
         If they are correctly encrypted (unmodified) then
             If the expiration date has not been reached AND the last-run date is older than the current date then
                 Run the application
                 Modify entry 3 to hold the current date (encrypted)
             Else if the last-run data is newer than the current date then
                 Somebody has tried to change system clock. Catch! :-)
             Else
                 The software has expired!
         Else
               Somebody tried to modify the encrypted values. Catch!
     Else
         If hidden entry 2 exists
             Somebody cleared the entries 1 and 3. Catch!
         Else
             This is the first run! Create entries 1, 2 and 3
     End if
    

  3. Sina Heidari 0 Reputation points
    2023-06-26T15:35:31.3766667+00:00

    It's late but I have implemented this algorithm:
    You need to implement AppConstants class with the values then it will work.

     private void CheckTrialVersion()
            {
                var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
    
                string startDayPath = $"Software\\{AppConstants.CompanyName}\\{AppConstants.SoftwareName}";
                string specialFilePath = $"Software\\{AppConstants.SpecialPath}\\{AppConstants.CompanyName}\\{AppConstants.SoftwareName}";
                string lastLoginDayPath = $"Software\\{AppConstants.CompanyName}\\{AppConstants.SoftwareName}";
    
                try
                {
                    RegistryKey startDay = key.OpenSubKey(startDayPath);
                    RegistryKey specialFile = key.OpenSubKey(specialFilePath);
                    RegistryKey lastLogin = key.OpenSubKey(lastLoginDayPath);
    
                    if (startDay != null && lastLogin != null)
                    {
                        var lastLoginTemp = lastLogin.GetValue(AppConstants.LastLogin);
                        var startDateTemp = startDay.GetValue(AppConstants.StartDay);
                        if (startDateTemp == null || lastLoginTemp == null)
                        {
                            MessageBox.Show("It seems somebody try to HACK the application!!!", "Access denied!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        var startDayValue = StringCipher.Decrypt(startDateTemp.ToString());
                        var lastLoginValue = StringCipher.Decrypt(lastLoginTemp.ToString());
                        if (DateTime.TryParse(startDayValue, out DateTime startDayDateValue) && DateTime.TryParse(lastLoginValue, out DateTime lastLoginDateValue))
                        {
                            if (startDayDateValue.AddDays(AppConstants.TrialPeriod) > DateTime.Now
                                            && lastLoginDateValue <= DateTime.Now)
                            {
                                Activated = true;
                                ModifyLastLogin();
                            }
                            else if (lastLoginDateValue > DateTime.Now)
                            {
                                MessageBox.Show("It seems Date and Time is modified!!!", "Date and Time problem", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                Globals.ThisAddIn.Application.WorkbookActivate -= Application_WorkbookActivate;
    
                            }
                            else
                            {
                                MessageBox.Show("Trial time is finished!!", "Expired", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                Globals.ThisAddIn.Application.WorkbookActivate -= Application_WorkbookActivate;
    
                                //todo: create a way to buy license.
                            }
                        }
                        else
                        {
                            MessageBox.Show("It seems somebody try to HACK the application!!!", "Access denied!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Globals.ThisAddIn.Application.WorkbookActivate -= Application_WorkbookActivate;
    
                        }
                    }
                    else
                    {
                        if (specialFile != null)
                        {
                            MessageBox.Show("It seems somebody try to HACK the application!!!", "Access denied!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            SetStartDay();
                            SetSpecialFile();
                            ModifyLastLogin();
                            Activated = true;
                        }
                    }
    
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"There is some problem with your activation license!!! Error:{ex.Message}", "Access denied!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
    
            }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.