1

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

Tamir Gefen
  • 1,128
  • 2
  • 18
  • 35
  • 3
    Note that if this is for a trialware thing, this is easily defeated. You should have protection in the application itself instead. – Miral Nov 05 '12 at 08:40
  • Having a date check is perfectly valid. The difference between software with a check (thats easy to beat) and one without anything is vastly greater than software with a check that's difficult to beat and one thats easy to beat. – Mr Purple Mar 06 '18 at 20:12

2 Answers2

5

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;
Lars
  • 1,428
  • 1
  • 13
  • 22
1

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;
Deanna
  • 23,876
  • 7
  • 71
  • 156
jachguate
  • 16,976
  • 3
  • 57
  • 98