请让我知道如何检查安装期间的当前日期。
我必须在安装程序脚本中嵌入特定日期,然后通知用户并停止安装过程,如果当前日期(从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函数,并将其与安装程序中某个地方的硬编码日期进行比较,例如在初始化期间,为我在此示例中为您做:
{lang:pascal}
[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;