Use openlicense to manage application licenses

Source: Internet
Author: User

Generally, commercial software imposes restrictions on their software products, such as the length of time and the number of times of use.

The license contains various restrictions, including:
1. length of time
2. Usage
3. Version Upgrade
4. Online Registration
The Open Source openlicenseis available at http://www.spextreme.com. Download and try it out. I think it is good.
Its main features are: creating licenses on a graphical interface, supporting product licenses, 512-bit encryption, license keys, various license restrictions, and support for design/operation.
Download open license here.

Here I will talk about the simplest way to set the license.

Use vs to create a Windows project licensedemo. By default, there is a form1. compile it once. Use the downloaded graphic interface to create the license file openlicensebuilder.exe.

Licensedemo.exe compiled just now

In this way, a beta constraint is added. Then, you can set the restrictions for its permission in the attribute window.

Save the file. Name it namespace. classname. Lic here as licensedemo. form1.lic and add the file to the vs project.

In form1, we want to test the license:

Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Using openlicense;
Namespace licensedemo
{
/// <Summary>
/// Summary of form1.
/// </Summary>
[Licenseprovider (typeof (openlicense. openlicenseprovider)]
Public class form1: system. Windows. Forms. Form
{
/// <Summary>
/// Required designer variables.
/// </Summary>
Private system. componentmodel. Container components = NULL;
Private license = NULL;
Public form1 ()
{
//
// Required for Windows Form Designer support
//
If (licensemanager. isvalid (typeof (form1), this, out license ))
{


If (license = NULL)
{
Throw new system. applicationexception ("A suable license file couldn't be found ");
}
Else if (openlicensefile) License). failurereason! = String. Empty)
{
Throw new system. applicationexception (openlicensefile) License). failurereason );
}

}
Else
{
MessageBox. Show ("no correct permission ");
}
Initializecomponent ();

//
// Todo: add Any constructor code after initializecomponent calls
//
}

/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}

# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. components = new system. componentmodel. Container ();
This. size = new system. Drawing. Size (300,300 );
This. Text = "form1 ";
}
# Endregion

/// <Summary>
/// Main entry point of the application.
/// </Summary>
[Stathread]
Static void main ()
{
Application. Run (New form1 ());
}
}
}

Note that you can add a password to the license file (LIC). The above license file is not encrypted. if you add a password, you need to go to assemblyinfo. add a line of code to the CS file to tell the password key. [Assembly: openlicense. assemblyopenlicensekey ("xxxxxx")]

The LIC file can be used as an embedded resource. however, during my official operation, I found that the execution path must have a license file. (If you need to run the program, copy the license file generated above to the bin directory .).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.