Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if restart is pending before installing in Inno Setup

Is there a way to prevent installation if a reboot/restart is already pending/required?

Our setup installs SQL Server Express and it will sometimes refuse to do so if there is a pending restart in the system. Can Inno Setup detect this condition so I can tell the user to reboot before installing our software?

I know about MakePendingFileRenameOperationsChecksum but it's usually mentioned to detect whether the reboot required condition appeared DURING the setup. Can it be used BEFORE?

like image 869
Goozak Avatar asked Dec 11 '25 02:12

Goozak


1 Answers

If you want to detect, if there is a pending rename that requires a restart, query PendingFileRenameOperations registry value.

See also How to find out if an MSI I just installed requested a Windows reboot?

function IsRestartPending: Boolean;
var
  S: string;
begin
  if RegQueryMultiStringValue(
       HKLM, 'SYSTEM\CurrentControlSet\Control\Session Manager',
       'PendingFileRenameOperations', S) then
  begin
    Log(Format('PendingFileRenameOperations value exists with value [%s]', [S]));
    Result := (Trim(S) <> ''); { This additional check is probably not needed }
  end
    else
  begin
    Log('PendingFileRenameOperations value does not exist');
    Result := False;
  end;
end;

function InitializeSetup(): Boolean;
begin
  if IsRestartPending then
  begin
    MsgBox('Restart your machine please', mbError, MB_OK);
    Result := False;
    Exit;
  end;

  Result := True;
end;

If you need to test for other actions that may need restart, you will have to adapt the answer by @Jerry for Inno Setup.

like image 186
Martin Prikryl Avatar answered Dec 13 '25 23:12

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!