【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, '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;

 

posted on 2020-05-13 13:23  liujx2019  阅读(365)  评论(0编辑  收藏  举报

导航