递增日期以使用 Inno Setup 实施试用期
Incrementing date to implement trial period using Inno Setup
我正在使用 Inno Setup 编译器为我的软件创建安装程序。安装程序在首次安装期间将时间戳添加到 Windows 注册表。重新安装软件时,它会检查 Windows 注册表中保存的时间戳,如果距离当前日期超过 90 天,那么它应该停止安装吗?所以我强制用户只能使用该软件 90 天。
我正在尝试将 90 天添加到当前日期时间以进行比较。在数据类型 TSystemTime
. I can add days to a TDateTime
变量中没有执行此操作的选项,但我无法在 Inno Setup 脚本中使用该变量。
这是我的代码
function InitializeSetup(): Boolean;
var
InstallDatetime: string;
begin
if RegQueryStringValue(HKLM, 'Software\Company\Player\Settings', 'DateTimeInstall', InstallDatetime) then
{ I want to add 90 days before comparison }
Result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), InstallDatetime) <= 0;
if not result then
MsgBox('This Software trial period is over. The Program will not install.', mbError, MB_OK);
Result := True;
end;
我在 Stack Overflow 上看到过类似的 example。他们使用常量来比较日期时间。相反,我将 90 天添加到我保存的安装日期时间。
任何帮助将不胜感激。
要递增 TSystemTime
,请选中 performing Arithmetic on SYSTEMTIME。
尽管在 Inno Setup 中实现 128 位运算可能很困难。
或者,您可以自己实现:
procedure IncDay(var Year, Month, Day: Integer);
var
DIM: Integer;
begin
Inc(Day);
case Month of
1, 3, 5, 7, 8, 10, 12: DIM := 31;
2: if (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0)) then
DIM := 29
else
DIM := 28;
4, 6, 9, 11: DIM := 30;
end;
if Day > DIM then
begin
Inc(Month);
Day := 1;
if Month > 12 then
begin
Inc(Year);
Month := 1;
end;
end;
end;
procedure IncDays(var Year, Month, Day: Integer; Days: Integer);
begin
while Days > 0 do
begin
IncDay(Year, Month, Day);
Dec(Days);
end;
end;
function IncDaysStr(S: string; Days: Integer): string;
var
Year, Month, Day: Integer;
begin
Year := StrToInt(Copy(S, 1, 4));
Month := StrToInt(Copy(S, 5, 2));
Day := StrToInt(Copy(S, 7, 2));
IncDays(Year, Month, Day, Days);
Result := Format('%.4d%.2d%.2d', [Year, Month, Day]);
end;
像这样使用它:
result :=
CompareStr(GetDateTimeString('yyyymmdd', #0,#0), IncDaysStr(InstallDatetime, 90)) <= 0;
我正在使用 Inno Setup 编译器为我的软件创建安装程序。安装程序在首次安装期间将时间戳添加到 Windows 注册表。重新安装软件时,它会检查 Windows 注册表中保存的时间戳,如果距离当前日期超过 90 天,那么它应该停止安装吗?所以我强制用户只能使用该软件 90 天。
我正在尝试将 90 天添加到当前日期时间以进行比较。在数据类型 TSystemTime
. I can add days to a TDateTime
变量中没有执行此操作的选项,但我无法在 Inno Setup 脚本中使用该变量。
这是我的代码
function InitializeSetup(): Boolean;
var
InstallDatetime: string;
begin
if RegQueryStringValue(HKLM, 'Software\Company\Player\Settings', 'DateTimeInstall', InstallDatetime) then
{ I want to add 90 days before comparison }
Result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), InstallDatetime) <= 0;
if not result then
MsgBox('This Software trial period is over. The Program will not install.', mbError, MB_OK);
Result := True;
end;
我在 Stack Overflow 上看到过类似的 example。他们使用常量来比较日期时间。相反,我将 90 天添加到我保存的安装日期时间。
任何帮助将不胜感激。
要递增 TSystemTime
,请选中 performing Arithmetic on SYSTEMTIME。
尽管在 Inno Setup 中实现 128 位运算可能很困难。
或者,您可以自己实现:
procedure IncDay(var Year, Month, Day: Integer);
var
DIM: Integer;
begin
Inc(Day);
case Month of
1, 3, 5, 7, 8, 10, 12: DIM := 31;
2: if (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0)) then
DIM := 29
else
DIM := 28;
4, 6, 9, 11: DIM := 30;
end;
if Day > DIM then
begin
Inc(Month);
Day := 1;
if Month > 12 then
begin
Inc(Year);
Month := 1;
end;
end;
end;
procedure IncDays(var Year, Month, Day: Integer; Days: Integer);
begin
while Days > 0 do
begin
IncDay(Year, Month, Day);
Dec(Days);
end;
end;
function IncDaysStr(S: string; Days: Integer): string;
var
Year, Month, Day: Integer;
begin
Year := StrToInt(Copy(S, 1, 4));
Month := StrToInt(Copy(S, 5, 2));
Day := StrToInt(Copy(S, 7, 2));
IncDays(Year, Month, Day, Days);
Result := Format('%.4d%.2d%.2d', [Year, Month, Day]);
end;
像这样使用它:
result :=
CompareStr(GetDateTimeString('yyyymmdd', #0,#0), IncDaysStr(InstallDatetime, 90)) <= 0;