Inno Setup iterate through users in Registry to remove entry for each users Run key
<p>I am looking to find a way to iterate through the users in the Registry i.e. the <code>HKEY_USERS</code> branch of the Registry) in order to remove an entry that might have been created by the application in the user's profile under <code>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run</code> when the software is uninstalled (i.e. in the uninstaller). My understanding is that each user has a unique SID e.g. <code>HKEY_USERS\S-1-5-21-1832913631-259515069-2567909844-16342</code> in the Registry. The objective therefore is to return a list of users SIDs in an array and then loop through removing the String value under <code>Run</code>.</p>
<p>I can use <code>RegGetSubkeyNames</code> to return the list of subkeys under <code>HKEY_USERS</code>:</p>
<pre class="lang-pascal prettyprint-override"><code>procedure RemoveAppRunRegEntries();
var
  Subkeys: TArrayOfString;
  I: Integer;
begin
  RegGetSubkeyNames(HKU, '', Subkeys);
  for I := 0 to GetArrayLength(Subkeys) - 1 do
    begin
      RegDeleteValue(HKU, Subkeys[I] + '\Software\Microsoft\Windows\CurrentVersion\Run',
        'App Run String Value');
    end;
end;
</code></pre>
<p>However, there are four default entries <code>.DEFAULT</code>, <code>S-1-5-18</code>, <code>S-1-5-19</code> and <code>S-1-5-20</code>, that I believe are always the same on every Windows installation (they are all on the installs I have checked under Windows 7 and 10), plus additional identical SIDs with <code>_Classes</code> appended to the the end, so for the example SID above, there is also a <code>HKEY_USERS\S-1-5-21-1832913631-259515069-2567909844-16342_Classes</code> subkey. Therefore, before looping through, I need to find a way of removing these entries from the array, so that I only have a list of the SIDs.</p>
<p>Is this the best approach to be taking and how might I remove the entries from the array to leave only the unique user SIDs? Is there anything else I have not thought of?</p>