Please let me know how to check the current date during the installation.
I have to embed a certain date in the installer script, and then notify the user and stop the installation process if current date (which is taken from Windows host) is bigger than hard-coded (embedded) date
Thank you
An alternative solution using Inno's built-in date routine 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;
You have to get the system date/time using the windows API, for example using the GetLocalTime function and compare that to your hard coded date somewhere in your installer, for example during initialization, as I did in this example for you:
{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;