interfaceuses 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); //设置试用期限30天 WriteInteger('Duration',30); //写入当前运行时间 WriteTime('LastRunTime',Date); end; end else begin ShowMessage('Fails!'); end; CloseKey; end; end;end.
interfaceuses
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);
//设置试用期限30天
WriteInteger('Duration',30);
//写入当前运行时间
WriteTime('LastRunTime',Date);
end;
end
else
begin
ShowMessage('Fails!');
end;
CloseKey;
end;
end;end.