Inno Setup: Create application valid for one year

╄→гoц情女王★ 提交于 2019-12-13 08:56:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/36823585/inno-setup-create-application-valid-for-one-year

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!