軟件試用期及試用次數控制
下面的代碼簡單演示了各部分的處理過程:
一、安裝時寫入加密數據:
(這裏的加密使用了控件)
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文件容基本相同!
上面的代碼只是初步的,如果你要使用,需要經過詳細的修改才對。由於是繁體版,部分註釋顯示為亂碼,我已經將註釋刪除了,裏面的.消息框裏的字符串也是亂碼,可以改改就行!敬原!
(注,本文只是推薦一種簡單的方法,以滿足在些朋友簡單的要求,代碼剛實現功能 ,存在很多問題,我才準備改改,有好的方法可以提出來!)迎大家提示好的方法。
-
計算機軟件許可合同
隨着人們法律觀念的日益增強,我們用到合同的地方越來越多,簽訂合同是為了保障雙方的利益,避免不必要的爭端。那麼大家知道合法的合同書怎麼寫嗎?以下是小編收集整理的計算機軟件許可合同,希望能夠幫助到大家。計算機軟件許可合同1答應方:______________________郵政...
-
計算機軟件實習報告彙編8篇
在人們素養不斷提高的今天,接觸並使用報告的人越來越多,我們在寫報告的時候要注意語言要準確、簡潔。那麼你真正懂得怎麼寫好報告嗎?以下是小編幫大家整理的計算機軟件實習報告,僅供參考,希望能夠幫助到大家。計算機軟件實習報告1一、實習計劃3月5日:參觀單位的基本...
-
計算機軟件管理制度2篇
在現在的社會生活中,越來越多人會去使用制度,制度是國家機關、社會團體、企事業單位,為了維護正常的工作、勞動、學習、生活的秩序,保證國家各項政策的順利執行和各項工作的正常開展,依照法律、法令、政策而制訂的具有法規性或指導性與約束力的應用文。大家知道制度...
-
計算機軟件著作權代理合同3篇
在人民愈發重視法律的社會中,越來越多的場景和場合需要用到合同,合同能夠促使雙方正確行使權力,嚴格履行義務。那麼我們擬定合同的時候需要注意什麼問題呢?以下是小編精心整理的計算機軟件著作權代理合同,僅供參考,大家一起來看看吧。計算機軟件著作權代理合同1甲方(...