【Inno Setup】检测是否需要预先重启

By Martin Prikryl

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, 'SYSTEMCurrentControlSetControlSession 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;
原文地址:https://www.cnblogs.com/liujx2019/p/12881823.html