软件试用期及试用次数控制
下面的代码简单演示了各部分的处理过程:
一、安装时写入加密数据:
(这里的加密使用了控件)
DES->GenerateKey(neowarton20030731);
TDateTime *d=new TDateTime(Date());
AnsiString times,date,filename;;
char dir[256];
times=0;
date=DateTimeToStr(*d);
times=DES->EncryptString(times);
date=DES->EncryptString(date);
//install=DES->EncryptString(date);
AnsiString s=times+date;
OutputDebugString(s.c_str());
filename=;
GetSystemDirectory(dir,sizeof(dir));
filename=dir+filename;
if(FileExists(filename))
{
Application->Terminate(); //if the ini file is alread exists exit;
}
else
{
TIniFile *ini=new TIniFile(filename);
ini->WriteString(setup,times,times);
ini->WriteString(setup,date,date);
ini->WriteString(setup,install,date);
ini;
//write register
TRegistry *reg=new TRegistry();
reg->RootKey=HKEY_LOCAL_MACHINE;
if(reg->KeyExists(SOFTWAREMicrosoftWindowsCurrentVersionmysoft))
Application->Terminate();//if the key exists,terminate
reg->OpenKey(SOFTWAREMicrosoftWindowsCurrentVersionmysoft,true);
reg->WriteString(warning,dot modify these items!Otherwise,your system will not run!neowarton2003xian);
reg->WriteString(times,times);
reg->WriteString(date,date);
reg->WriteString(install,date);
reg->CloseKey();
reg;
}
二、安装时在install Shield中加入以下代码:
Lauchapp(SUPPORTDIR^,) //test为上面代码的exe文件
其它代码省略
三、在应用程序起动时:
bool rt;
TForm1 *fm1=new TForm1(NULL);//试用版弹出的窗口,点击试用返回判断结果
fm1->ShowModal();
rt=fm1->try_time;//是否已经过期
fm1;
if(rt)
{
MessageBox(NULL,¥?3n?é??¥?′á¤v1L?A§A¤£ˉà|A¨?¥??óa?¥??A?Dáê?R¥?|?a??I ,ˉ?2t¥D?÷o?μ?¨?¤?àe,MB_OK+MB_ICONINFORMATION);
Application->Terminate();//??3?à3¥?μ{§?
return 0;
}
四、用户点击试用按钮,返回是否过期的bool值:
//read the encrypted ini file in the system directory to read the time and date
//if filenote exist,return false,if the time and date wrong return false;
//read data and then time from the register,where the data is also encrypted
char dir[256];
AnsiString filename=;
GetSystemDirectory(dir,sizeof(dir));
//the ini fils is in the system directory
filename=dir+filename;
if(!FileExists(filename))
{
Application->MessageBox(§Aao¨t2?1?¥?3n¥ó?i|?¤F?Dak-ק??A¤w?g¤£ˉà|A¨?¥??I,ˉ?2t¥D?÷¨?¤?àe,MB_ICONERROR);
HWND H;
H=FindWindow(NULL,DNAAlarm);
::SendMessage(H,WM_CLOSE,0,0);
OutputDebugString(go here);
this->try_time=true;
Close();
return;
}
TIniFile *ini=new TIniFile(filename);
AnsiString times,datetime,installday;
times=ini->ReadString(setup,times,);
datetime=ini->ReadString(setup,date,);
installday=ini->ReadString(setup,install,);
getthepara();
AnsiString tt=times_reg+|+datetime_reg+|+datetime_reg;
AnsiString ttt=times+|+datetime+|+installday;
if((times_reg!=times)||(datetime_reg!=datetime)||(installday!=datetime_reg))
{
this->try_time=true;
}
else //------------------------------------
{
DES->GenerateKey(neowarton20030731);
times=DES->DecryptString(times);
datetime=DES->DecryptString(datetime);
installday=DES->DecryptString(installday);
times_reg=DES->DecryptString(times_reg);
datetime_reg=DES->DecryptString(datetime_reg);
installday_reg= DES->DecryptString(installday_reg);
tt=times_reg+|+datetime_reg+|+datetime_reg;
ttt=times+|+datetime+|+installday;
//|r2?|ê?à′?|¨¤é′á
int t=StrToInt(times);
TDateTime *dt=new TDate(Date());
TDateTime *s=new TDate(StrToDate(datetime)); TDateTime *install=new TDate(StrToDate(installday));
int tmp=*dt-*s;
int tmp2=*dt-*install;
//int tmp3=*s-*dt;
if((tmp>=-1)&&(tmp<=90)&&(tmp2>=-1)&&(tmp2<=90)&&(t<150))
{
AnsiString times_tmp=DES->EncryptString(IntToStr(StrToInt(times)+1));
AnsiString datetime_tmp=DES->EncryptString(DateTimeToStr(*dt));
ini->WriteString(setup,times,times_tmp);
ini->WriteString(setup,date,datetime_tmp);
putthepara(times_tmp,datetime_tmp);
this->try_time=false;
}
else
{
//write wrong time;
AnsiString times_tmp=DES->EncryptString(IntToStr(StrToInt(times)+200));
AnsiString datetime_tmp=DES->EncryptString(DateTimeToStr(*dt+3000));
ini->WriteString(setup,times,times_tmp);
ini->WriteString(setup,date,datetime_tmp);
putthepara(times_tmp,datetime_tmp);
this->try_time=true;
}
}
ini;
this->Close();
五、ini文件:
[setup]
times=inAk6xcTevw=
date=XOqvDla+r+2Xtl4ZM567cQ==
install=kAP2X5LVcWaXtl4ZM567cQ==
(数据已经加密)
.....
六、注表容INI文件容基本相同!
上面的代码只是初步的,如果你要使用,需要经过详细的修改才对。由于是繁体版,部分注释显示为乱码,我已经将注释删除了,里面的.消息框里的字符串也是乱码,可以改改就行!敬原!
(注,本文只是推荐一种简单的方法,以满足在些朋友简单的要求,代码刚实现功能 ,存在很多问题,我才准备改改,有好的方法可以提出来!)迎大家提示好的方法。
-
华为c8500每次安装软件都提示解析包时错误
这是怎么回事啊以前都不会的现在软件都下载不了了…还有智汇云里面怎么没有东西了空的这是怎么回事求解拜托各位了...
-
计算机软件专业求职信(13篇)
时间是箭,去来迅疾,我们又将面临求职找工作的挑战,此时此刻需要开始写求职信了哦。那么如何写求职信才简练、明确呢?以下是小编帮大家整理的计算机软件专业求职信,欢迎大家借鉴与参考,希望对大家有所帮助。计算机软件专业求职信1尊敬的经理:您好!我的名字叫xx,听到贵公...
-
计算机软件专业求职信10篇
日子在弹指一挥间就毫无声息的流逝,求职时间的高峰期马上到来,需要认真地为此写一封求职信了。如何把求职信做到简练、明确呢?以下是小编帮大家整理的计算机软件专业求职信10篇,欢迎阅读,希望大家能够喜欢。计算机软件专业求职信篇1尊敬的公司领导:您好!感谢您能百忙...
-
计算机软件实习报告汇编5篇
在当下这个社会中,接触并使用报告的人越来越多,报告具有成文事后性的特点。那么什么样的报告才是有效的呢?下面是小编为大家整理的计算机软件实习报告,仅供参考,希望能够帮助到大家。计算机软件实习报告1对计算机有了更具体认识,透过对计算机的具体操作和亲自实践巩...