请让我知道如何在安装过程中检查当前日期。
我有嵌入在安装程序脚本一定的日期,然后通知用户时,如果当前的日期(从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;