Search code examples
inno-setuprebootpascalscript

Inno Setup doesnt restart at PrepareToInstall section


I am trying to prompt the user to restart the computer after enabling .NET 3.5, which is necessary for MSSQLServer. Example:

function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
  Log('PrepareToInstall() called');
  GetWindowsVersionEx(Version);
  if (Version.Major = 10) then begin
   NeedsRestart :=True;
  end
end;

Am i missing something?


Solution

  • NeedsRestart parameter is considered only if PrepareToInstall event function actually aborts an installation (by returning a non-empty string). What you probably do not want to do. In other words, you are abusing PrepareToInstall event function (and incorrectly anyway).

    Use NeedRestart event function instead:

    [Code]
    
    function NeedRestart(): Boolean;
    var
      Version: TWindowsVersion;
    begin
      GetWindowsVersionEx(Version);
      Result := (Version.Major >= 10);
    end;