-1

I test my software with new code.

const MY_EXPIRY_DATE_STR = '20131112'; //Date format: yyyymmdd

function InitializeSetup(): Boolean;
var
  ErrorCode: Integer;
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
    begin
    MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
end 
      if (MsgBox('Autocad will compulsory closed,so please save your drawings and then press OK', mbConfirmation, MB_OK) = IDOK) then
         begin
           ShellExec('open', 'taskkill.exe', '/f /im acad.exe','', SW_HIDE, ewNoWait, ErrorCode);
           ShellExec('open', 'tskill.exe', ' ACAD', '', SW_HIDE, ewNoWait, ErrorCode);
           Result := True;
         end
       else
         begin
           Result := False;
         end;
    end;

The issue is the setup show the error message (Now it's forbidden to install this program) but it continue install. I want it exit the installer.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Mohamed Ahmed
  • 113
  • 11

1 Answers1

3

You're forgetting to return from the function when your expiry condition is met.

This

  if not result then
    begin
    MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
end 

should be:

  if not Result then
    begin
      MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
      Exit;
    end;

Without the Exit, the following statements execute with the possibility of setting Result to 'True' again.

Notice also the formatting. If you had it right, there is a good chance that you wouldn't be asking this question.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • that is work great thanks Sertac Akyuz.but i have another question.if i set the date what ever i want. what happen to software after reach this date. i want it uninstall it self. – Mohamed Ahmed Apr 24 '16 at 17:04
  • 1
    @Mohamed - That is a different question that you'd want to ask separately. However I can tell the installer cannot do that by itself, it won't be even running when your program expires. IMO the installer shouldn't have any part in this at all, the program should be checking and refusing to run - the user can then choose to uninstall it. – Sertac Akyuz Apr 24 '16 at 17:12
  • sorry Sertac Akyuz i'm totally new in programming and use inno setup a few days ago.thanks for your help again i will make a new question. notice my software its just copy and past some folders and files for Autocad. and i use inno setup to do that.so that's why i want uninstall it after one year – Mohamed Ahmed Apr 24 '16 at 17:36