问题
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