Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup: Don't install if file exists [duplicate]

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!

like image 600
Davdson Avatar asked Jan 01 '26 05:01

Davdson


1 Answers

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.

like image 144
Martin Prikryl Avatar answered Jan 06 '26 12:01

Martin Prikryl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!