Click here to Skip to main content
Click here to Skip to main content

Implementing a Rudimentary Count Based Trial Version Plugin for Windows Applications

By , 23 Apr 2012
Rate this:
Please Sign up or sign in to vote.

Introduction

This tip describes a very rudimentary approach to implement a trial version of an application that will open for some predefined number of times.

Background

Many a times, we want to demonstrate our application with full functionality to someone. While doing so, there is a risk of that application being used at the other end. This small tip describes a very quick way of implementing a Trial version in an application so that the application can only be opened for some limited number of times.

The approach defined in this article is very rudimentary and if it is used as is, then expert user can circumvent this version checking (full/trial) with very little effort. Perhaps using this approach in conjunction with encryption/decryption and little bit customization of logic will make it more robust for commercial use.

Note: This plugin uses a registry component found at CodeProject here.

Using the Code

What we are doing here is we are keeping a track of number of times the application has been run in Windows registry. We will check for the number of times the application has been opened. If the user is allowed to open the application, we will let him run the application and increase the count in the registry. If the number of count increases the acceptable runs in trial version, then we will not start the application.

If the user chooses to make this application a full version, then there is a separate registry entry. A simple code to change the registry value will convert the application to full version without the user needing to install this application again.

Here is the simple class that is handing this logic:

class VersionChecker
{        
    static int currentRun = 1;
    static string RegistryPath = "Software\\Rahul";
    static string TrailVersionKey = "TVS";
    static string FullVersionKey = "FVS";
    const int TRAIL_RUNS = 5;

    public static bool IsValidVersion()
    {
        RegistryComponent registry = new RegistryComponent(RegistryPath, false);

        string strFullVersion = registry.Read(FullVersionKey);
        string strTrailVersion = registry.Read(TrailVersionKey);

        // If this exist then the user is perhaps using the full version
        if (strFullVersion == null)
        {
            //this could be the first run
            if (strTrailVersion == null)
            {
                //this is the first run definitely
                registry.Write(TrailVersionKey, currentRun.ToString());
            }
            else
            {
                //not the first run
                currentRun = Convert.ToInt32(strTrailVersion);
                currentRun += 1;

                registry.Write(TrailVersionKey, currentRun.ToString());

                //Let us check whether is has exhausted all his trail attempts or not
                if (currentRun > TRAIL_RUNS)
                {
                    //The user has exhausted all his trail runs, do not let him in
                    return false;
                }
            }
        }

        //User is either using the full version or still has some trails left, let him pass through
        return true;
    }
}

To use this component, we will have put a check at the application start up as:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    if (VersionChecker.IsValidVersion() == true)
    {
        Application.Run(new Form1());
    }
    else
    {
        MessageBox.Show("Your trail version has expired, Please get the full version");
    }
}

The application will only run for 5 times in this particular case. 

Points of Interest

This small code facilitates having a trial version for any Windows application. However if the registry editing is not allowed on a user machine, then this approach will not work. Then we will have to keep a separate configuration file keeping track of this information.

There is a lot of scope for improvement in this application. We can have features like encryption/decryption, custom logic instead of counts, having some particular key written while updating to full version to make this more robust.

Also, with some changes, we can easily change this plugin to have a time based trial version. We just have to track time instead of count in that case.

Note: The core of this approach is the class handling registry editing which can be found here.

History

  • 23 April 2012: First version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Rahul Rajat Singh
Software Developer (Senior)
India India
I Started my Programming career with C++. Later got a chance to develop Windows Form applications using C#. Currently using C#, ASP.NET & ASP.NET MVC to create Information Systems, e-commerce/e-governance Portals and Data driven websites.

My interests involves Programming, Website development and Learning/Teaching subjects related to Computer Science/Information Systems. IMO, C# is the best programming language and I love working with C# and other Microsoft Technologies.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 1 PinmemberFerretallicA23-Apr-12 21:04 
GeneralMy vote of 2 Pinmemberleppie23-Apr-12 1:55 
AnswerRe: My vote of 2 PinmemberRahul Rajat Singh23-Apr-12 2:32 
GeneralMy vote of 4 Pinmemberleppie23-Apr-12 2:54 
QuestionIt's not "trail" PinmemberHüseyin Tüfekçilerli22-Apr-12 23:45 
AnswerRe: It's not "trail" PinmemberRahul Rajat Singh23-Apr-12 1:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 23 Apr 2012
Article Copyright 2012 by Rahul Rajat Singh
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid