Click here to Skip to main content
15,798,405 members
Articles / Programming Languages / C#

Implementing a Rudimentary Count Based Trial Version Plugin for Windows Applications

Rate me:
Please Sign up or sign in to vote.
4.13/5 (8 votes)
23 Apr 2012CPOL2 min read 24.3K   862   8   6
Implementing a Rudimentary Count Based Trial Version Plugin for Windows Applications


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


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());
                //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:

static void Main()

    if (VersionChecker.IsValidVersion() == true)
        Application.Run(new Form1());
        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.


  • 23 April 2012: First version


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

Written By
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.

  • Microsoft Certified Technology Specialist (MCTS): Web Applications Development with Microsoft .NET Framework 4
  • Microsoft Certified Technology Specialist (MCTS): Accessing Data with Microsoft .NET Framework 4
  • Microsoft Certified Technology Specialist (MCTS): Windows Communication Foundation Development with Microsoft .NET Framework 4

If you like my articles, please visit my website for more:[^]

  • Microsoft MVP 2015

Comments and Discussions

GeneralMy vote of 1 Pin
FerretallicA23-Apr-12 22:04
FerretallicA23-Apr-12 22:04 
GeneralMy vote of 2 Pin
leppie23-Apr-12 2:55
leppie23-Apr-12 2:55 
AnswerRe: My vote of 2 Pin
Rahul Rajat Singh23-Apr-12 3:32
professionalRahul Rajat Singh23-Apr-12 3:32 
GeneralMy vote of 4 Pin
leppie23-Apr-12 3:54
leppie23-Apr-12 3:54 
QuestionIt's not "trail" Pin
Hüseyin Tüfekçilerli23-Apr-12 0:45
Hüseyin Tüfekçilerli23-Apr-12 0:45 
AnswerRe: It's not "trail" Pin
Rahul Rajat Singh23-Apr-12 2:33
professionalRahul Rajat Singh23-Apr-12 2:33 

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

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