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

Application Trial Maker

, 16 Feb 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
A library to easily create a trial version of your application



It's very common to want a trial version of your application. For example, you need your application to only run for 30 days, or the user can only run your application 200 times.

You can do this kind of task with this library.

If someone wants to buy your application, he must call you and read his computer ID. Then you will use the Serial Maker to make a serial key (password). After entering the password, the application always runs as the full version.

If the trial period is finished, reinstalling the application won't let user run it.

The computer ID is a 25 character string that came from hardware information. Processor ID, main board manufacturer, VGA name, hard disk serial number, etc. You can choose what hardware items you want to use to make the computer ID.

When you give the password to a customer, his password won't change until he changes his hardware.

Computer ID

To make a Computer ID, you must indicate the name of your application. That's because if you have used Trial Maker to make a trial for more than one application, each application will have it's own Computer ID. In the source, Computer ID = "BaseString"

Trial Maker uses management objects to get hardware information.


The password will be produced by changing the Computer ID. To make a password, you must have your own identifier. This identifier is a 3 character string. None of characters must be zero.


There are two files to work with in this class.

The first file is used to save computer information and remaining days of the trial period. This file must be in a secure place, and the user must not find it (RegFile). It's not a bad idea to save this file in application startup directory

The second file will be used if the user registers the software. It will contain the serial that the user entered (HideFile). You can save HideFile in, for example, C:\Windows\system32\tmtst.dfg. I mean some obscure path.

Both files will be encrypted using Triple DES algorithm. The key of encryption is custom. It's better you choose your own key for encryption.

How it works

Getting System Information

SystemInfo class is for getting system information. It contains the GetSystemInfo function. This function takes the application name and appends to it the Processor ID, main board product, etc.

public static string GetSystemInfo(string SoftwareName)
    if (UseProcessorID == true)

        SoftwareName += RunQuery("Processor", "ProcessorId");

    if (UseBaseBoardProduct == true)

        SoftwareName += RunQuery("BaseBoard", "Product");

    if (UseBaseBoardManufacturer == true)

        SoftwareName += RunQuery("BaseBoard", "Manufacturer");
    // See more in source code

    SoftwareName = RemoveUseLess(SoftwareName);

    if (SoftwareName.Length < 25)

        return GetSystemInfo(SoftwareName);
    return SoftwareName.Substring(0, 25).ToUpper();

Then it removes unused characters from the string. Any characters outside the range A to Z and 0 to 9 are unused characters. If the string isn't long enough, call GetSystemInfoAgain to make it longer.

RunQuery function takes object name (TableName) and method name and returns defined method of first object

private static string RunQuery(string TableName, string MethodName)
    ManagementObjectSearcher MOS =
      new ManagementObjectSearcher("Select * from Win32_" + TableName);
    foreach (ManagementObject MO in MOS.Get())
            return MO[MethodName].ToString();
        catch (Exception e)
    return "";

Once we have system information, we must make a Computer ID (BaseString) from it.

Making Computer ID (BaseString)

private void MakeBaseString()
    _BaseString = 

To make BaseString, first we get system information, and then use Encryption.InverseByBase and Encryption.Boring.

InverseByBase: Encryption.InverseByBase("ABCDEF",3) will return CBAFED; it's so simple - it's inversing every 3 characters

Boring: move every character in the string with the formula:

NewPlace = (CurrentPlace * ASCII(character)) % string.length

Making Serial key (Password)

We use Encryption.MakePassword. this function takes BaseString and Identifier. It uses InverseByBase 3 times and Boring once, and then use ChangeChar function to change characters

static public string MakePassword(string st, string Identifier)
    if (Identifier.Length != 3)
        throw new ArgumentException("Identifier must be 3 character length");
    int[] num = new int[3];
    num[0] = Convert.ToInt32(Identifier[0].ToString(), 10);
    num[1] = Convert.ToInt32(Identifier[1].ToString(), 10);
    num[2] = Convert.ToInt32(Identifier[2].ToString(), 10);
    st = Boring(st);
    st = InverseByBase(st, num[0]);
    st = InverseByBase(st, num[1]);
    st = InverseByBase(st, num[2]);

    StringBuilder SB = new StringBuilder();
    foreach (char ch in st)
        SB.Append(ChangeChar(ch, num));
    return SB.ToString();

Check Password

After making BaseString and password, check if the user already registered the software. To do this, use CheckRegister Function. It will return true if registered before and false if not.

If CheckRegister returns false, open a registration dialog for the user to enter the password.

Show Dialog

Create new frmDialog and show it to the user. If the dialog result is OK, it means software is registered successfully, and if it is Retry, it means it is in trial mode. Any other DialogResult means cancel. The Dialog class takes BaseString, Password, days to end and Run times to end as arguments.

Reading And Writing Files

There's a class named FileReadWrite. This class reads / writes files with Triple DES encryption algorithm.

FileReadWrite.WriteFile take a 2 strings. The first one is the file path and the second one is the data to write. After writing all data it write byte 0 as finish. It will use for reading

public static void WriteFile(string FilePath, string Data)
    FileStream fout = new FileStream(FilePath, FileMode.OpenOrCreate,
    TripleDES tdes = new TripleDESCryptoServiceProvider();
    CryptoStream cs = new CryptoStream(fout, tdes.CreateEncryptor(key, iv),
    byte[] d = Encoding.ASCII.GetBytes(Data);

    cs.Write(d, 0, d.Length);


The key for writing and reading is the same one, it's custom and you can change it.

How To Use

Where to use

The best place that you can check for registration is before showing the main dialog. When you have created a Windows application project, first you must add SoftwareLocker.dll as reference

Then in program.cs, find the main function. I think it's the best place for checking registration. You can check registration when your main dialog loads, but before loading is better.

Change Main Dialog

It's better to add one argument to your main dialog constructor. A Boolean value that indicates that this is a trial or a full version running. If it's a trial mode, disable some parts of your application as needed.

How to change main()

Add namespace

using SoftwareLocker;
static void Main()

    TrialMaker t = new TrialMaker("TMTest1",
      Application.StartupPath + "\\RegFile.reg",
      Environment.GetFolderPath(Environment.SpecialFolder.System) +
      "Phone: +98 21 88281536\nMobile: +98 912 2881860",
      5, 10, "745");

    byte[] MyOwnKey = { 97, 250,  1,  5,  84, 21,   7, 63,
                         4,  54, 87, 56, 123, 10,   3, 62,
                         7,   9, 20, 36,  37, 21, 101, 57};
    t.TripleDESKey = MyOwnKey;
    // if you don't call this part the program will
    //use default key to encryption

    TrialMaker.RunTypes RT = t.ShowDialog();
    bool is_trial;
    if (RT != TrialMaker.RunTypes.Expired)
        if (RT == TrialMaker.RunTypes.Full)
            is_trial = false;
            is_trial = true;

        Application.Run(new Form1(is_trial));

Don't move first two lines, after them, define TrialMaker class


  • SoftwareName: Your software's name, this will be used to make ComputerID
  • RegFilePath: The file path that, if the user entered the registration code, will save it and check on every run.
  • HiddenFilePath: This file will be used to save system information, days to finish trial mode, how many other times user can run application and current date.
  • Text: It will show below the OK button on the Registration Dialog. Use this text for your phone number, etc.
  • DefaultDays: How many days the user can run in trial mode.
  • DefaultTimes: How many times user can run the application.
  • Identifier: Three character string for making password. It's the password making identifier

Optional and recommended

In the constructor, you can change the default Triple DES key. It's a 24 byte key, and then you can customize Management Objects used to make the Computer ID (BaseString):

t.UseBiosVersion = false // = true;

You can do this with any t.UseXxx

Don't disable all of them or none of them, enabling 3 or 4 of them is the best choice. Or you can leave it as its default.

Serial Maker

Serial maker is another application that uses the Encryption class. It takes your identifier and generate a password (serial key)

Doesn't contain anything special.

Other Controls

In the registration dialog, I have used a SerialBox control. It's only 5 text boxes that you can write your serial in.

SerialBox uses FilterTextBox itself.

Both of these controls are available to download.


  • All codes are written in Visual Studio 2005
  • Serial Maker uses Encryption class from Trial Maker as a file link
  • Writing with one encryption key and reading with another will cause an exception
  • FilterTextBox Control is not the same that I wrote before in my articles
  • Always Secure your identifiers and don't lose them


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


About the Author

Hamed J.I
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I began programming with C/C++ when i was 15. Then try to learn VC++ but at the middle of my reading .NET came.
I began to read C# and VB.NET and also began designing basic websites by FrontPage and developed some websites for our school and some other companis.
Later learn Microcontroller and design some digital circuits with PIC microcontrollers for a industrial controller company.
As I learned SQL and ASP.NET developed some website such as news portals that are active now.
Now i'm a software student and teach programming in computer institues. And have my own job by getting projects from companies.

Comments and Discussions

QuestionHow to use it on PinmemberNikhil Bhivgade7-Mar-13 1:41 
QuestionNice Artical Pinmembersureshanumula14-Dec-12 2:10 
GeneralMy vote of 5 PinmemberMember 414767420-Nov-12 23:49 
QuestionAdministrator Pinmemberegypogramer30-Oct-12 17:12 
GeneralComment PinmemberMember 868749129-Oct-12 2:31 
GeneralMy vote of 5 PinmemberJack_32117-Oct-12 20:32 
GeneralMy vote of 5 PinmemberMember 86517734-Oct-12 9:54 
QuestionSoftware locker .dll is not working. Pinmember143Deepak23-Sep-12 8:16 
QuestionPLEASE EXPLAIN ME :WHAT IS Identifier ? WHAT MEAN 3 DIGIT? Pinmemberqhai7-Sep-12 19:14 
AnswerRe: PLEASE EXPLAIN ME :WHAT IS Identifier ? WHAT MEAN 3 DIGIT? Pinmembergeekbond13-Oct-12 1:43 
GeneralRe: PLEASE EXPLAIN ME :WHAT IS Identifier ? WHAT MEAN 3 DIGIT? PinmemberVISHAL nakate24-Apr-13 0:46 
GeneralRe: PLEASE EXPLAIN ME :WHAT IS Identifier ? WHAT MEAN 3 DIGIT? Pinmemberbehzad20006-May-13 8:33 
GeneralMy vote of 5 PinmemberIMRAN SHAFQA31-Aug-12 22:57 
Questionthis is not working in vs2008 Pinmemberricha arora1421-Aug-12 5:30 
this is not working in vs 2008.the unauthorised acess exception
AnswerRe: this is not working in vs2008 Pinmembergeekbond13-Oct-12 1:50 
QuestionAccess to the path 'C:\Windows\system32\TMSetp.dbf' is denied. Pinmemberricha arora1420-Aug-12 1:38 
AnswerRe: Access to the path 'C:\Windows\system32\TMSetp.dbf' is denied. Pinmembergeekbond13-Oct-12 1:46 
QuestionBut not security Pinmembernguyenanh26031-Jul-12 16:53 
AnswerRe: But not security PinmemberXaltus8-Aug-12 6:14 
AnswerRe: But not security Pinmembermyregistercd12-Dec-12 20:43 
QuestionSerial Maker not working..( Visual Studio 2010 ) PinmemberAgit yıldız31-Jul-12 10:14 
QuestionCan Anyone Translate it? PinmemberASHISH' PORWAL1-Jul-12 0:31 
QuestionError while running path Pinmembersatish1nov5-Jun-12 7:36 
AnswerRe: Error while running path PinmemberDau Le Trung23-Jun-12 13:49 
AnswerRe: Error while running path Pinmembernilesh_1349016-Aug-12 3:55 
GeneralNice piece of work Pinmembergeekbond25-May-12 0:50 
Questionhow to change trail duration PinmemberMember 82336017-May-12 22:26 
Questionchange trail period...? Pinmemberbalagp3-May-12 18:36 
GeneralMy vote of 2 Pinmemberbarbodsoft3-May-12 2:27 
Questionhow to identify in sebBaseString TrialMakker? Pinmemberrengaraj1232-Apr-12 10:26 
AnswerRe: how to identify in sebBaseString TrialMakker? Pinmembersicos corp.23-Nov-12 17:29 
Questionhow to renew PinmemberMember 796459629-Feb-12 23:15 
Questionthanks , but .... Pinmembernassimnastaran29-Feb-12 10:50 
AnswerRe: thanks , but .... Pinmemberfagot_t2-Mar-12 5:03 
GeneralMy vote of 5 Pinmembermanoj kumar choubey22-Feb-12 1:31 
QuestionpLEASE eXPLAIN Pinmemberdipan chikani17-Jan-12 5:27 
GeneralMy vote of 5 Pinmemberharath randika17-Jan-12 0:13 
GeneralMy vote of 2 PinmemberSakthi Manoj R29-Dec-11 3:04 
Generalthank you Pinmemberamertarekt12-Dec-11 21:34 
Questionthank you Pinmemberdjramc26-Nov-11 5:14 
Questionthanks Pinmembermahmoud mansourinejad2-Nov-11 11:47 
QuestionTrial PinmemberxFabioxSantos6-Oct-11 6:06 
QuestionSerial Maker not working.. Pinmemberkishore30927-Sep-11 7:52 
Questionto win 7 Pinmemberdreje201029-Aug-11 12:53 
AnswerRe: to win 7 Pinmemberbirjulodhiya17-Dec-11 8:58 
GeneralMy vote of 5 Pinmemberaisha_hamoda6-Jul-11 15:08 
Generalhi Hamed_ji! Pinmemberpcthao2-Jul-11 22:01 
GeneralMy vote of 5 Pinmemberpcthao2-Jul-11 21:56 
QuestionProblem with SerialMarker PinmemberKrasti22-May-11 1:16 
Answer[SOLVED] Re: Problem with SerialMarker PinmemberKrasti22-May-11 3:03 

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 | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 17 Feb 2009
Article Copyright 2006 by Hamed J.I
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid