请让我知道如何在安装过程中检查当前日期。
我必须在安装程序脚本中嵌入某个日期,然后如果当前日期(取自 Windows 主机)大于硬编码(嵌入)日期,则通知用户并停止安装过程
谢谢
请让我知道如何在安装过程中检查当前日期。
我必须在安装程序脚本中嵌入某个日期,然后如果当前日期(取自 Windows 主机)大于硬编码(嵌入)日期,则通知用户并停止安装过程
谢谢
使用 Inno 的内置日期例程GetDateTimeString的替代解决方案。
[Code]
const MY_EXPIRY_DATE_STR = '20131112'; //Date format: yyyymmdd
function InitializeSetup(): Boolean;
begin
//If current date exceeds MY_EXPIRY_DATE_STR then return false and exit Installer.
result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), MY_EXPIRY_DATE_STR) <= 0;
if not result then
MsgBox('This Software is freshware and the best-before date has been exceeded. The Program will not install.', mbError, MB_OK);
end;
您必须使用 Windows API 获取系统日期/时间,例如使用GetLocalTime函数,并将其与安装程序中某处的硬编码日期进行比较,例如在初始化期间,正如我在此示例中为您所做的那样:
{语言:帕斯卡}
[Code]
type
TSystemTime = record
wYear: Word;
wMonth: Word;
wDayOfWeek: Word;
wDay: Word;
wHour: Word;
wMinute: Word;
wSecond: Word;
wMilliseconds: Word;
end;
procedure GetLocalTime(var lpSystemTime: TSystemTime); external 'GetLocalTime@kernel32.dll';
function DateToInt(ATime: TSystemTime): Cardinal;
begin
//Converts dates to a integer with the format YYYYMMDD,
//which is easy to understand and directly comparable
Result := ATime.wYear * 10000 + aTime.wMonth * 100 + aTime.wDay;
end;
function InitializeSetup(): Boolean;
var
LocTime: TSystemTime;
begin
GetLocalTime(LocTime);
if DateToInt(LocTime) > 20121001 then //(10/1/2012)
begin
Result := False;
MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
end
else
begin
Result := True;
end;
end;