Search code examples
installationinno-setuppascalscript

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


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!


Solution

  • 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 allows customizing an installation path, you won't know it, when re-running the installation after uninstallation. So this won't work.