Delphi实现限定软件使用时间的方法
Delphi实现限定软件使用时间的方法
本文所述实例代码功能就是如何为Delphi所编写的程序添加使用时间的限制功能,这里默认的时限为30天。
主要代码如下:
unit Unit1;
interface
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Registry,Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R .DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
registerTemp : TRegistry;
curDate : TDateTime;
begin
registerTemp := TRegistry.Create;
with registerTemp do
begin
RootKey := HKEY_LOCAL_MACHINE;
//判断是否初次运行程序
if OpenKey('Software\MySoftware',True) then
begin
if ReadBool('Runned') then
//不是第一次运行
begin
curDate := Date;
if (curDate-ReadTime('LastRunTime'))>=ReadInteger('Duration') then
begin
//当前的系统时间超出了使用期限
ShowMessage('试用版已到期');
exit;
end
else
begin
DeleteKey('LastRunTime');
WriteTime('LastRunTime',Date);
end;
end
else
begin
//初次运行程序
DeleteKey('Runned');
WriteBool('Runned',True);
//设置试用期限3656=2190天(6年)
WriteInteger('Duration',2190);
//写入当前运行时间
WriteTime('LastRunTime',Date);
end;
end
else
begin
ShowMessage('Fails!');
end;
CloseKey;
end;
end;
end.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了