Inno Setup: Close installer wizard if file exists in the program's folder

左心房为你撑大大i 提交于 2020-03-15 07:35:59

问题


I am trying to create an installer that is a Demo installer that if it detects the file close.txt in the programs folder then it closes the wizard or aborts install.

I am running a scheduled task that automatically uninstalls the app after two days. On initial install the close.txt file gets installed in the programs folder then after auto uninstall the close.txt file is left in the programs folder. I would like for when you re run the installer it checks for this file and if it is found to close the wizard or abort install. I am a newbie at this I think it can be accomplished in the code section but I am not sure.

Any help or code snippets would be appreciated thank you!


回答1:


Test for the file existence in InitializeSetup event function and return False, if it exists.

[Setup]
DefaultDirName={autopf}\My Program
[Code]
function WasMyProgramEverInstalled: Boolean;
begin
  Result := FileExists('{#SetupSetting("DefaultDirName")}\close.txt');
end;

function InitializeSetup: Boolean;
begin
  Result := True;
  if WasMyProgramEverInstalled then
  begin
    MsgBox('Some message', mbError, MB_OK); { Optionally }
    Result := False;
  end;
end;

Note that if the installer allow customizing an installation path, you won't know it, when re-running the installation after uninstallation. So this won't work.



来源:https://stackoverflow.com/questions/60460128/inno-setup-close-installer-wizard-if-file-exists-in-the-programs-folder

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