title: How do I know if a restart is needed in InnoSetup script?
body: <p><strong>TL;DR version:</strong></p>
  
  <p>In an InnoSetup script, how can I detect if a restart is needed because of files that were in use?</p>
  
  <p><strong>More detailed version:</strong></p>
  
  <p>I have an Inno Setup script with the following characteristics:</p>
  
  <ul>
  <li><p>the <code>ShouldSkipPage</code> function is implemented so that all pages (except the welcome page) are skipped unless a custom "Advanced options" checkbox on the welcome page is checked:</p>
  
  <pre><code>function ShouldSkipPage(PageID: Integer): Boolean;
  begin
      if ((PageID = wpSelectDir) or
          (PageID = wpSelectProgramGroup) or
          (PageID = wpSelectTasks) or
          (PageID = wpFinished) or
          (PageID = wpReady)) then
      begin
          Result := not advancedCheckBox.Checked;
      end;
  end;
  </code></pre></li>
  <li><p><code>CloseApplications</code> and <code>RestartApplications</code> are set to <code>false</code> (*), and some files have the <code>restartreplace</code> and <code>uninsrestartdelete</code> flags, so a restart will be required to complete the installation if the files were in use</p></li>
  </ul>
  
  <p>Now, if a restart is needed, I want to show the Finished page regardless of the state of the "Advanced options" checkbox, because I don't want to cause a restart without prompting the user. So my code would be something like that:</p>
  
  <pre><code>    function ShouldSkipPage(PageID: Integer): Boolean;
      begin
          if ((PageID = wpSelectDir) or
              (PageID = wpSelectProgramGroup) or
              (PageID = wpSelectTasks) or
              (PageID = wpReady)) then
          begin
              Result := not advancedCheckBox.Checked;
          end
          else if ((PageID = wpFinished)) then
          begin
              Result := (not advancedCheckBox.Checked) and (not IsRestartNeeded);
          end
      end;
  </code></pre>
  
  <p>Unfortunately, there is no <code>IsRestartNeeded</code> function (<code>NeedRestart</code> exists, but it's an event function). I spent a long time looking at the documentation, but I didn't find any function that could give me this information.</p>
  
  <p>The only option I can think of is to look at <code>HKLM\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations</code> to see if it contains any of my files, but it's a rather ugly solution...</p>
  
  <hr>
  
  <p>(*) The files I want to replace or remove are a shell extension and some DLLs used by this extension. The reason why I'm not relying on the Restart Manager is because it doesn't seem to work with <code>explorer.exe</code>: the process is immediately restarted, and my files are locked again.</p>