How to use Inno Setup Flags: restartreplace but without restarting

100 Views Asked by At

I created a setup installation package by Inno Setup. Recently, I developed a COM component for the program. But due to its DLL being locked, it must be updated the next time it starts up Windows. I used Flags: restartreplace. It works well.

However, two of my clients have given me feedback that they would like to no longer remind me to "restart my computer". They said they accidentally restarted the computer, causing data loss in their other software. I think so too. In fact, when installing a new version, the old version can still be used normally. Because restartreplace will only be replaced the next time the computer is started, it does not affect usage at all, so there is no need to restart the computer.

So, is there a way when using Flags: restartraplace, the installation package is working properly, and users cannot see any restart option. They can also directly display "Start Program" as usual after the installation is completed?

1

There are 1 best solutions below

0
Martin Prikryl On BEST ANSWER

I do not think there's an easy solution for this. I have a similar setup. What I do:

  • If the same version of the problematic file is installed already, I do not try to install it again, preventing the conflict in the first place.

  • If it has to be replaced, but the replace is not critical, I programmatically reset the "Finished" page back to the standard layout (without restart).

    The code is like this (this does not involve the RunList, as for other reasons, I replace the standard Run/postinstall feature with my custom one).

    WizardForm.YesRadio.Visible := False;
    WizardForm.NoRadio.Visible := False;
    WizardForm.NoRadio.Checked := True;
    
    S := SetupMessage(msgFinishedLabel);
    StringChange(S, '[name]', 'My Program');
    WizardForm.FinishedLabel.Caption :=
      S + NewLine + NewLine +
      SetupMessage(msgClickFinish) + NewLine;
    

Full code is here:
https://github.com/winscp/winscp/blob/master/deployment/winscpsetup.iss
Notable parts are in ShouldInstallShellExt and CurPageChanged (CurPageID = wpFinished).


Another option is to code the replacement yourself. To replicate what Inno Setup does (but without forcing restart):

  • Use ExtractTemporaryFile function to extract the file from the installer. Or just "install" the file to a temporary location (Inno Setup uses .tmp extension appended to the destination path).
  • Try to delete the already installed version.
  • If that fails, schedule a replacement on the next restart using RestartReplace function.
  • If delete succeeds, rename the temporary file to the target name.

Roughly like this:

var
  DestFile, TempFile: string;
ExtractTemporaryFile('my.dll');
TempFile:= ExpandConstant('{app}\my.dll.tmp');
DestFile:= ExpandConstant('{app}\my.dll');
FileCopy(ExpandConstant('{tmp}\my.dll'), TempFile, False);
if DeleteFile(DestFile) then
begin
  RenameFile(TempFile, DestFile);
end
  else
begin
  RestartReplace(TempFile, DestFile);
end;

(not tested – might not even compile – and need a lot of error checking and logging)