程序把授权文件保存到sqlserver数据库里,每次启动会从数据库里读取授权,如果数据库里没有,就引发异常,CheckLicense()这个函数监测到异常就关闭程序。这个程序没加密,直接修改就行
[C#] 纯文本查看 复制代码 public object ReadLicense(int manualid)
{
LicenseManager licenseManager = new LicenseManager(manualid);
string text = string.Empty;
SqlCeConnection sqlCeConnection = new SqlCeConnection(this.m_connstr);
sqlCeConnection.Open();
SqlCeCommand sqlCeCommand = new SqlCeCommand("select license from t_license", sqlCeConnection);
text = sqlCeCommand.ExecuteScalar().ToString();
Exception ex = null;
LicenseInfo result = null;
try
{
result = licenseManager.getLicenseInfo(text);
}
catch (Exception ex2)
{
ex = ex2;
int num = 0;
int.TryParse(text, out num);
if (num > 10)
{
ex = new SecurityException("已经达到试用次数上限,请注册");
}
num++;
SqlCeCommand sqlCeCommand2 = new SqlCeCommand("update t_license set license ='" + num.ToString() + "'", sqlCeConnection);
sqlCeCommand2.ExecuteNonQuery();
}
sqlCeConnection.Close();
if (ex != null)
{
throw ex;
}
return result;
}
[C#] 纯文本查看 复制代码 private void CheckLicense()
{
if (this.m_manual_id > 0)
{
try
{
object obj = this.m_EMData.ReadLicense(this.m_manual_id);
}
catch (Exception ex)
{
if (!(new winRegistor
{
Owner = this,
ManualID = this.m_manual_id,
ManualVersion = this.m_manual_version,
emdata = this.m_EMData
}.ShowDialog() == true))
{
if (ex.GetType() == typeof(SecurityException))
{
SystemMessageBox.ShowError(ex.Message);
System.Windows.Application.Current.Shutdown();
}
}
}
} |