Quick Start using “Unlock Key” licensing schema
Sample written in C#
Sample written in Visual Basic .NET

Manco .NET Licensing System provides many different ways to license.NET products. The most popular way is licensing by secure “Unlock Key”. We’ve selected it to give quick start instructions to you. Many steps are described in this topic are similar for most licensing schemas.

Firstly you need understand how the “Unlock Key” licensing schema works. When customer downloads your application from the Internet he or she gets an evaluation version. It will start out in evaluation mode, limited by the number of days the customer can run it. When the customer buys your application, he or she will receive an unlock key, enter it into the application, and get not limited, fully functional application.

Now you need prepare all necessary licensing information and integrate license protection to your application. License Manager is the tool that is used to prepare licensing information. It also helps integrate license protection to your application. Go to the Windows Start menu at the “All Programs->Manco Software->Licensing System” and click License Manager. If you are still running it in evaluation mode, you will have to first close the licensing dialog before you get to the main application window.

License Dialog

Click “OK” button to close it. The main application window appears:

License Manager

The protection library uses information stored in the license file to check license validity. Firstly it tests whether the license file is used with right product and version. To get this information included to the license file you should now create Product and Version descriptions in the License Manager.

Click License Manager - Add New Product toolbar button. The new product description will be created:

License Manager - Product

You should enter product name, company name and description. Protection library uses product name and company name to test protected product validity. To pass this test both this fields MUST match the fields in the Assembly Info of your .Net application. To find these fields in your product:

  1. Open your .NET project in the Visual Studio.
  2. Double-click “Properties” node under your project name in the Solution Explorer.
  3. Click “Application” tab.
  4. Press the “Assembly Information” button. The “Assembly Information” dialog will appear:
Visual Studio - Assembly Information

The “Company” field in this dialog must have exactly the same value as filed “Company” in License Manager has. The “Product” field in this dialog must have exactly the same value as filed “Name” in License Manager has:

License Manager - My Application

After double checking that they match, you can now create version description.

Click License Manager - Add New Version toolbar button when product node is selected in the left tree view. New version description will be created. Set version number so it has same value as “Assembly Version” in the “Assembly Information” dialog has.

License Manager - New Version

You also must fill in the “Default File Name”. This field should contain name of the license file that will be used by your system. It can be any valid file name with any extension you’d like, but we suggest you name your license files so you could detect what it is for using file name. You can leave default value in other fields for now.

Now you should create License Type that will allow your application operate as you desire: application will start out in evaluation mode, limited by the number of days the customer can run it. When the customer buys your application, he or she will receive an unlock key, enter it into the application, and get not limited, fully functional application.

To create new license type click License Manager - Add New License Type toolbar button. New license type will be created. Name it (for example, “Licensed by Unlock Key”). In Manco .NET Licensing System the way how protection library operates is set by list of the license rules included to the license type. You should include following rules to the license type: “Expiration Dates”, “Is Evaluation”, “Unlock Key” and “Write Key to file”. Mark these rules in the list of available rules and click License Manager - Include license rules button. Your license type definition now should looks like the following:

License Manager - Unlock Key license type

Included license rules operate as following:

Expiration Dates – set number of days during which your product will work in evaluation mode. This license rule can be used to create evaluation. When someone attempts use licensed product after given number of days it will give “Your license has been expired” exception.

Is Evaluation – indicates, that license is in evaluation mode. Allows you limit some functionality in your product using evaluation status of license.

Unlock Key – including of this validation rule to the base license file allows you using of the “Unlock Key” schema to activate product. It informs protection library that Unlock Key provided by customer should be validated.

Write Key To File – indicates whether the “Unlock Key” should be written to the protected storage after validation. If you don’t use this rule, then customer will be asked for Unlock Key every time when your application starts.

Now you should create evaluation license file. This file will be distributed with your application. It will contain all necessary licensing information, such as the number of evaluation days available, and the Unlock Key needs to be saved to the protected storage. To do this, you need to add a sale under this license type. We call it “evaluation sale”.

Click License Manager - Add New Sale toolbar button. Now you should see a window with many fields for customer information, and a section for license parameters at the bottom. First, you should put for customer name “License File” so that you can recognize it from your other sales later on. Next, go down to the License Parameters section. Check Write Key to File, and choose how many days of evaluation use you want your customers to have before the evaluation expires.

License Manager - Sale window - Evaluation

Pay attention, “Unlock Key” field in this record MUST be empty. Click OK to add new sale.

Save all changes made in the License Manager. To do it click License Manager - Save all changes toolbar button. All records have been created in the License Manager will be saved in the database. The next step is to integrate license protection into your .NET application.

Pay attention, “Unlock Key” field in this record MUST be empty. Click OK to add new sale.

Firstly you should add two references to your project. One is the Manco.Licensing DLL, which can be found here, “C:\Program Files\Manco Software\Manco.Licensing System\DLL\Manco.Licensing.dll”, and the other is System.Web. The System.Web reference is needed internally by the Manco.Licensing DLL.

For Windows desktop application (either Windows Forms or Windows Presentation Foundation) the best place to insert base licensing code is main application window class.

Check that System.ComponentModel and Manco.Licensing namespaces are imported to your class:

[C#]
using System.ComponentModel;
using Manco.Licensing;
    
[Visual Basic]
Imports System.ComponentModel
Imports Manco.Licensing
    

Next, put this line of code directly above your class definition:

[C#]
[LicenseProviderAttribute(typeof(Manco.Licensing.LicenseProvider))]
	
[Visual Basic]
<LicenseProvider(GetType(Manco.Licensing.LicenseProvider))> _
	

Manco .NET Licensing System requires that protected class implements Manco.Licensing.ILicenseKeyProvider interface. You must include this interface to the list of the interfaces are implemented by your class. To perform operations on the license (validate it or check expiry status) you should include object of Manco.Licensing.License type to your class. Finally your class definition code could look like following:

[C#] 
[LicenseProviderAttribute(typeof(Manco.Licensing.LicenseProvider))]
public partial class MainForm : Form, ILicenseKeyProvider
{
	private Manco.Licensing.License license;

	…
}
	
[Visual Basic] 
<LicenseProvider(GetType(Manco.Licensing.LicenseProvider))> _
Public Class MainForm
	Implements ILicenseKeyProvider

	Private license As Manco.Licensing.License

	…

End Class
			

Now you must include implementation of the ILicenseKeyProvider interface to your code. License Manager can prepare this code for you. Right click on the version number in the tree view (3.2.0.0)

License Manager - ILicenseKeyProvider

Select “Generate ILicenseKeyProvider Code” and choose programming language that you are using, and you will see a dialog pop up with code:

License Manager - ILicenseKeyProvider

Click “To Clipboard” button. Go to your project and paste code to the protected class. You will need to make one change, however. In the property BypassExpirationCheck, instead of returning “false”, return “true”. This will make it so that Manco.Licensing DLL doesn’t throw an exception if the license is expired, and so that you can handle it yourselves.

[C#]
/// <summary>
/// Indicates whether the expiration check should be performed
/// inside the license constructor.
/// </summary>
public bool BypassExpirationCheck
{
	get
	{
		// Default return value is false. We change it to true
		// so we could bypass expiration check in the constructor 
		// of the license object so it wouldn't throw exception 
		// and we could use license object to show license information
		// in the license dialog.
		return true;
	}
}
    
[Visual Basic]
''' <summary>
''' Indicates whether the expiration check should be performed
''' inside the license constructor.
''' </summary>
Public ReadOnly Property BypassExpirationCheck() As Boolean _
Implements Manco.Licensing.ILicenseKeyProvider.BypassExpirationCheck
	Get
		' Default return value is false. We change it to true
		' so we could bypass expiration check in the constructor 
		' of the license object so it wouldn't throw exception 
		' and we could use license object to show license information
		' in the license dialog.
		Return True
	End Get
End Property
    

The best place to initialize license variable is class constructor (method “New” in VB.NET). You also need pass information about calling and licensed assembly to the license object:

[C#]
public MainForm()
{
	…

	// Instantiate license object and assign assemblies will be validated
	license = (Manco.Licensing.License)LicenseManager.Validate(
		typeof(MainForm), this);
	license.CallingAssembly = typeof(MainForm).Assembly;
	license.LicensedAssembly = typeof(MainForm).Assembly;
}
    
[Visual Basic]
Sub New()
	…

	' Instantiate license object and assign assemblies will be validated
	license = LicenseManager.Validate(GetType(MainForm), Me)
	license.CallingAssembly = GetType(MainForm).Assembly
	license.LicensedAssembly = GetType(MainForm).Assembly
End Sub
    

Next, the program needs to check to see the status of the license. If it is evaluation, or not valid, a dialog needs to be shown that allows the user to input an Unlock Key. We leave implementation of the evaluation window on your own, so you can put anything you’d like to it. The simple form can contain notification text and text field Unlock Key. You should provide a way to get entered key from the form and put it to the “UnlockKey” property of the license object. It looks like the best place for this code is “OnLoad” event handler:

[C#]
private void MainForm_Load(object sender, EventArgs e)
{
	// Check if the current license is evaluation license or not valid
	if (license.IsEvaluation || !license.IsValid)
	{
		// This is evaluation or not valid license, 
		// so we should show evaluation dialog 
		LicenseForm loForm = new LicenseForm();
		loForm.License = license;
		if (loForm.ShowDialog() == DialogResult.OK
			&& loForm.UnlockKey.Trim() != string.Empty)
		{
			// License information have been entered.
			// Pass it to the license object for the
			// following validation.
			license.UnlockKey = loForm.UnlockKey;
		}
		else if (license.IsExpired)
		{
			// The evaluation license has been expired and 
			// no license information have been entered, 
			// so we should close application.
			Application.Exit();
		}
	}

	// Now you can use license object to validate license. 
	// License will be valid if it is evaluation license,
	// or entered valid Unlock Key.
	if (license.IsValid)
	{

		// Initialize application
		// Make some GUI elements available only when
		// Unlock Key have been entered (license is valid 
		// and is not evaluation one).
		tsmiAvailableWhenUnlocked.Enabled = !license.IsEvaluation;
		tsbAvailableWhenUnlocked.Enabled = !license.IsEvaluation;
		txtAvailableWhenUnlocked.Enabled = !license.IsEvaluation;
	}
	else
	{
		// License not valid – wrong unlock key has been entered
		// or wrong license file is used 
		MessageBox.Show("License Not Valid",
			"Sample Application",
			MessageBoxButtons.OK,
			MessageBoxIcon.Stop);
		Application.Exit();
	}
}
    
[Visual Basic]
Private Sub MainForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
	' Check if the current license is evaluation license or not valid
	If license.IsEvaluation Or Not license.IsValid Then
		' This is evaluation or not valid license, so 
		' we should show license dialog 
		Dim loForm As LicenseForm = New LicenseForm()
		loForm.License = license
		If loForm.ShowDialog() = DialogResult.OK _
		  And loForm.UnlockKey.Trim() <> String.Empty Then
			' License information have been entered.
			' Pass it to the license object for the
			' following validation.
			license.UnlockKey = loForm.UnlockKey
		ElseIf license.IsExpired Then
			' The evaluation license has been expired and 
			' no license information have been entered, 
			' so we should close application.
			Application.Exit()
		End If
	End If

	' Now you can use license object to validate license. 
	' License will be valid if it is evaluation license,
	' or entered valid Unlock Key.
	If license.IsValid Then
		' Initialize application
		' Make some GUI elements available only when
		' Unlock Key have been entered (license is valid 
		' and is not evaluation one).
		tsmiAvailableWhenUnlocked.Enabled = Not license.IsEvaluation
		tsbAvailableWhenUnlocked.Enabled = Not license.IsEvaluation
		txtAvailableWhenUnlocked.Enabled = Not license.IsEvaluation
	Else
		' License not valid – wrong unlock key has been entered
		' or wrong license file is used 
		MessageBox.Show("License Not Valid", _
		 "Sample Application", _
		 MessageBoxButtons.OK, _
		 MessageBoxIcon.Stop)
		Application.Exit()
	End If
End Sub
    

Now we should add evaluation license file to your project. “Unlock Key” licensing scheme requires only one license file that will be redistributed with application. The best practice is to include this license file to your project as embedded resource.

Create new folder in your project and call it “License”:

Visual Studio - Solution Explorer

In the License Manager select license type node, switch to the “Sales” tab and select “License File” sale you’ve created early.

License Manager - Evaluation Sale

Click License Manager - Save license file toolbar button. In the “Save File” dialog select location for license file so it will be in “License” folder inside your project. Save file.

In the Visual Studio solution explorer right click the “License” folder and select “Add->Existing Item”. In the “Add Existing Item” dialog select license file to add it into your project. In the solution explorer select file you’ve added and go to the “Properties” window. Set “Build Action” to the “Embedded Resource” for this file.

Visual Studio - Embedded Resource

Now you application is ready to run. First time you start it you will see evaluation window with field to enter “Unlock Key”. If you simple close this window your application will continue execution in the evaluation mode. You can check this mode using “IsEvaluation” property of the license object. You can enable or disable some functionality or GUI controls based on this status. To get your application fully functional you have to create “Unlock Key” for it.

Click License Manager - Add new sale toolbar button. You will “Add new sale” window. Enter necessary customer information. Actually it is enough enter customer name and e-Mail, but we would recommend at least First and Last name too. Click License Manager - Search customer toolbar button to perform search of the client through the database. Click License Manager - Generate Unlock Key toolbar button to generate Unlock Key.

License Manager - Real Sale

Click OK to add new sale. Save all changes made in the License Manager. To do it click License Manager - Save all changes toolbar button. All records have been created in the License Manager will be saved in the database.

Now you can copy and paste “Unlock Key” have been generated to the evaluation form and get your application fully functional. Protection library will store valid Unlock Key in the protected storage, so your customers will not be requested for it next time they start your application.


Sample written in C#
Sample written in Visual Basic .NET
.NET Licensing Pro Home Page