Using Activation Service.
Sample written in C#
Sample written in Visual Basic .NET

The Manco Licensing System includes (optionally) Activation Web Service that allows activate licenses so that they can be used only on one PC at a time. Product activation is a technology used by a number of licensing schemes available today. Manco Licensing System allows you using product activation to fasten a license to a single computer so that the same license can’t be used on another PC.

Configure Activation Web Service

First what you should do after installation of the Activation Web Service is setup database access.

  1. Open Web.config with any text editor.
  2. Under <appSettings> section find <add> element with key="ActivationService.ConnectionString".
  3. In the “value” attribute find following substring “Data Source=[DATABASE_PATH]\LicenseGenerator.mdb;”
  4. Change [DATABASE_PATH] so it point to the same database file that is used by Manco.License Generator. This file is located in the Manco.Licensing System installation folder (By default it is C:\Program Files\Manco\Manco.Licensing System).

Prepare product to use Activation Schema

Activation Web Service automatically sends e-Mail with activation key to user. For this purposes you should configure activation letter for every product to use with activation schema.

  1. Add new e-Mail configuration corresponding to the activation letter (see e-Mail Configurations in the documentation).
  2. Save changes.
  3. Select Activation Letter for the version of the product (see Version View in the documentation).

To set licensing schema use activation key you should add “Activation Key” field to the corresponding license type.

  1. Select license type that will use product activation schema (see License Type View in the documentation).
  2. Check “Activation Key” in “Available Fields” list and click -> button.

In your project add form that would perform product activation. Depends on what base licensing schema (License File or Unlock Key) you are using for your product this form could contain text box for Unlock Key. Add button for activation, text box for Activation Key and button to accept activation key and close form. In case of using “Unlock Key” schema those form could looks like the following:

License Activation Form

Add Web Reference to the activation server to your product:

  1. Right click on the corresponding project in the Solution Explorer in the Visual Studio.
  2. In the context menu click “Add Web Reference”.
  3. In the “Add Web Reference” dialog fill in “URL” field so it point to the Activation Service (something like http://yourhost/ActivationService/ActivationService.asmx).
  4. Click “Go” button. Wait till information about activation service will be obtained.
  5. Change Web reference name and click “Add Reference” button.
Add Web reference

Add “On Click” event handler to your license activation form. This handler should pass the “Unlock Key” (if applicable) to the license object, obtain product ID and send it to the activation server. In case of using “Unlock Key” schema prospective code could looks like the following:

[C#] 
private void cmdActivate_Click(object sender, System.EventArgs e)
{
	// If "Unlock Key" has been entered
	if(txtUnlockKey.Text.Trim() != string.Empty)
	{
		// Pass "Unlock Key" to the license object
		m_License.UnlockKey = txtUnlockKey.Text.Trim();
		// Get instance of the Activation Service
		ActivationService.ActivationService loActivationService = 
			new ActivationService.ActivationService();
		try
		{
			// Get product ID from the license and try to activate product
			if(loActivationService.ActivateProduct(m_License.ProductID))
			{
				// In case when product succesfully activated user 
				// will recieve e-Mail with activation code.
				MessageBox.Show(
					"Activation Key has been succesfully generated."
					+ " Check your e-Mail box for it");
			}
		}
		catch(Exception exc)
		{
			MessageBox.Show("Exception during activation:\n" + exc.ToString());
		}
	}
	else
	{
		MessageBox.Show("Enter Unlock Key to be able activate product");
	}
}
			

The calling code for license activation form could looks like the following

[C#]
// Instantiate license object and assign assemblies will be validated
license = (Manco.Licensing.License)LicenseManager.Validate(typeof(MainForm), this);
license.CallingAssembly = System.Reflection.Assembly.GetCallingAssembly();
license.LicensedAssembly = System.Reflection.Assembly.GetExecutingAssembly();

// Now you can use license object to validate license you provided with your product. 
// It could be unlock key or license file, in any case validation should be done by 
// checking IsValid property of the license object. 
// In case of the using Unlock Key with Activation license has evaluation status
// till both Unlock and Activation Keys are entered.
if(license.IsEvaluation)
{
	LicenseForm loForm = new LicenseForm();
	loForm.License = license;
	if(loForm.ShowDialog() == DialogResult.OK 
		&& loForm.UnlockKey.Trim() != string.Empty
		&& loForm.ActivationKey.Trim() != string.Empty)
	{
		license.UnlockKey = loForm.UnlockKey;
		license.ActivationKey = loForm.ActivationKey;
	}
}

if(!license.IsValid)
	throw new Exception("Illegal use of the sample application");

Activation Web Service automatically sends e-Mail with activation key to user. So you should have at least customer e-Mail to get this schema works. All necessary information on customer should be obtained during preparing license file, generating unlock key or from separate sale service. If valid purchase information isn’t exists in the database, then Activation Web Service suppose that this is attempt of hacking and throw exception. Don’t forget enter customer’s e-Mail if you are using Product Activation Schema.

Validate Activation Key through the Internet

Another valuable feature of the Activation Web Service is ability to validate Activation Key through the Internet. It’s up to you to configure your application to use this feature. Your application can connect with Activation Web Service to check if the licensing information (license file or Unlock Key) and Activation Key are valid and stop execution if they aren’t. So if you remove Activation Key or information about purchase from the database your application will not work (in case of money back, for example). To allow your licensed product validate activation key through the Internet you should include to your application code that looks like the following:

[C#]
// If license isn't evaluation, then request validation on the Activation Web Service
if(!license.IsEvaluation)
{
	// It seems that license has been activated already. Validate it using Activation Web Service
	// Get instance of the Activation Service
	ActivationService.ActivationService loActivationService = new ActivationService.ActivationService();
	try
	{
		// Validate product ID against the Activation Key
		if(!loActivationService.ValidateProduct(license.ProductID, license.ActivationKey))
		{
			// Activation server couldn't validate activation key against product id
			throw new Exception("Illegal use of the sample application");
		}
	}
	catch(Exception exc)
	{
		MessageBox.Show("Exception during activation:\n" + exc.ToString());
		Application.Exit();
	}
}
.NET Licensing Pro Home Page