unit TrialDate;interfaceuses Base64Unit,System.Win.Registry,Winapi.Windows,System.SysUtils, System.Classes,Vcl.Controls;function TrialDate(TrialInt:Integer):Integer;implementation//==============================================================================// 软件试用天数设置——写入到注册表中// 作者:键盘记忆//日期:2021年4月29日23点34分//==============================================================================function TrialDate(TrialInt:Integer):Integer;var Reg:TRegistry; RegStr,TempStr:String; CountInt:Integer; MyCount:Double; begin RegStr := ''; TempStr := ''; CountInt := 0; MyCount:= 0; try Reg := TRegistry.Create; //创建对象 Reg.RootKey := HKEY_CURRENT_USER; RegStr := '\Software\Trial'; if Reg.OpenKey(RegStr,False) then TempStr := Reg.ReadString('TrialDate'); Reg.CloseKey; if TempStr = '' then //第一次试用 begin if Reg.OpenKey(RegStr,True) then begin Reg.WriteString('TrialDate',Base64Encryption(DateToStr(Date))); Reg.WriteString('TrialCount',Base64Encryption('1')); end; Reg.CloseKey; Result := 1; end else begin //当前系统日期<TrialDate ,试用日期已经到了 if Date<StrToDate(Base64Decryption(TempStr)) then begin if Reg.OpenKey(RegStr,False) then Reg.WriteString('TrialCount',Base64Encryption(IntToStr(TrialInt))); Reg.CloseKey; Result := 0; Exit; end; if Reg.OpenKey(RegStr,False) then CountInt := StrToInt(Base64Decryption(Reg.ReadString('TrialCount'))); Reg.CloseKey; //如果TrialDate=当前系统日期,最后试用日期为当天 if Date = StrToDate(Base64Decryption(TempStr)) then begin Result := CountInt; Exit; end; MyCount := Date - StrToDate(Base64Decryption(TempStr)); CountInt := CountInt + Trunc(Mycount); if CountInt > TrialInt then begin if Reg.OpenKey(RegStr,False) then begin Reg.WriteString('TrialDate',Base64Encryption(DateToStr(Date))); Reg.CloseKey; Result := 0; Exit; end; Result := CountInt; if Reg.OpenKey(RegStr,False) then begin Reg.WriteString('TrialDate',Base64Encryption(DateToStr(Date))); Reg.WriteString('TrialCOunt',Base64Encryption(IntToStr(CountInt))); end; Reg.CloseKey; end; Reg.Destroy; end; except on E: Exception do Result := -1; end; end;end.
不论试用信息存储在注册表还是文件,应给予用户两种提示方式:方式一:“软件试用了几天”;方式二:“软件还剩多少天”(图片来源网络,侵删)
0 评论