为了保护软件的著作权,又想让用户有个好的体验,我们需要设计软件评估期,这里贴一个用C#实现软件评估期30天的限制的实例代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Infralution.Licensing.CF;
namespace Geoff.DeviceApplication
{
public partial class Form1 : Form
{
const string LICENSE_PARAMETERS =
@"<LicenseParameters>
<RSAKeyValue>
<Modulus>rzRJ6dZ4ZTJ8/EzFtq2XIaik7QBSc24b8i8KJrPaxXGiCMDFcj8JtEFePa1SYX1W3cQoiwvCAF/MYmkXto74WdApYzILel+bOHSaUXTImrxpPtykNhPD7fF3PEXxrLRrTjUWQyEX5+XSaNPstmbDJw/Zg83mraCfmGeLcsiEypM=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
<DesignSignature>GJYsK2rQE7uj539+QCyJ3Z2GyrNEZQNxruxOQR6P2jo+Ze3Ev5Kgbf3N33RaLf7oEUsZNF4Gv7w5UFgYcdHzCphqznt4vcR++u9tb0sC5m6hf26538GXhkNodyVR9FDcv1AX4+PaM/kY+Z8mrMMmC148lYPpCHypXvgjOmDd9oQ=</DesignSignature>
<RuntimeSignature>coZIUnOTaRZCIa67HBMM6/xbkQNYS+l4ROeLmzn7SqRamBwP7cbfOEAsxlFV2roKlY6oz1B91/PYcTVPLfWahwjHaiAaLjKAosXK41yZOozu0vRWpv4H9ERiEli0pYX0M8fMBIkvSDT6n9X9T/6U4ujyefv8b4IxbYsB3zsjjx0=</RuntimeSignature>
<KeyStrength>7</KeyStrength>
</LicenseParameters>";
const string LICENSE_FILE = "Licensed.lic";
public Form1()
{
InitializeComponent();
EncryptedLicenseProvider provider = new EncryptedLicenseProvider();
EncryptedLicense license = provider.GetLicense(LICENSE_PARAMETERS, LICENSE_FILE);
if (license == null)
{
LicenseInstallForm licenseForm = new LicenseInstallForm();
license = licenseForm.ShowDialog("DeviceApp", LICENSE_FILE);
if (license != null)
{
MessageBox.Show("程式授权");
}
}
if (license == null)
{
EvaluationMonitor monitor = new EvaluationMonitor("DeviceApp");
if (monitor.DaysInUse > 30 || monitor.Invalid)
{
MessageBox.Show("程式评估期限过期");
Application.Exit();
}
else
{
MessageBox.Show(string.Format("程式30天评估期,已使用{0}天", monitor.DaysInUse));
}
}
}
}
}