How to cancel installation using Inno Setup?

I am using Inno install to install my product, in setup I run an external program (Validator.exe) if this program is canceled or interrupted. I have to cancel my own installer.

I save Validator.exe in the {app} path and execute it.

When the installer is running, I call the Validator.exe file and get the execution result: Exec (ExpandConstant ('{app} /Validator.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode).

But these are the problems with all the solutions I've tried:

InitializeSetup: Validator.exe has not yet been copied to {app}, so it will never be executed.

Undo: Can only be called in (InitializeSetup, InitializeWizard, CurStepChanged (ssInstall)), so in these cases the Validator hasn't been copied yet.

DeinitializeSetup: I can execute Validator.exe after installation, but I cannot cancel my installer from this point.

I need to somehow undo the installation after Validator.exe has been copied and executed, maybe uninstall it, but I couldn't do it.

Thanks for any help.

+1


a source to share


3 answers


You can simply use the ExtractTemporaryFile () helper function to extract validator.exe at any earlier stage of the installation. See question inno setup to fetch files at initial setup instead of end and my answer to it.



+4


a source


In Inno Setup, an "external" file is a file that is not included in the installer EXE file. It exists externally, presumably as a separate file with an installer EXE file. You say that your reason for not calling Abort

on the event InitializeSetup

is because the checker has not yet been copied into the directory {app}

, which is understandable since at this point the user has not yet indicated what the installation location should be. But you don't need a validator on the destination directory. This is already an external file, so just run it from whatever directory it is already in.



Another possibility is to add the required checking functionality to the DLL. You can include the DLL in the installer, and Inno Setup will extract the DLL to a temporary location so that you can call its functions from the install script.

+2


a source


Thanks, it works great. This is how I fixed it:

function InitializeSetup(): Boolean;.
var
  ResultCode : Integer;
begin
  Result := True;
  ExtractTemporaryFile('Validator.exe');

  if Exec(ExpandConstant('{tmp}\Validator.exe'), '', '', SW_SHOW,
    ewWaitUntilTerminated, ResultCode)
  then begin
    if not (ResultCode = 0) then begin
      Result := false;
    end;
  end;
end;

      

+2


a source







All Articles