title: Registering a COM without Admin rights
body: <p>I want to register a .net assembly as COM.</p>
  
  <p>In fact what that means as far as I know is, that instead of <code>HKEY_CLASSES_ROOT</code> I want the entries to be written in <code>HKEY_CURRENT_USER/Software/Classes</code>, so that UAC/Admin rights are not needed.</p>
  
  <p>Found two solutions of that problem, with both I'm struggling:</p>
  
  <p>1) <strong>Programmatically way</strong>, with following code:</p>
  
  <pre><code>        IntPtr key;
          var openKeyresult = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Classes", 0, (int)RegistrySecurity.KEY_WOW64_64KEY, out key);
          var overrideKeyResult = RegOverridePredefKey(HKEY_CLASSES_ROOT, key);
          var registerResult = Registrar.RegisterAssembly(GetAssembly(), AssemblyRegistrationFlags.SetCodeBase);
  </code></pre>
  
  <p>in this approach, <code>overrideKeyResult</code> is 6 which corresponds to ERROR_INVALID_HANDLE, thus, the <code>RegisterAssembly</code> throw a "access denied" exception because it tries to write to <code>HKEY_CLASSES_ROOT</code>.</p>
  
  <p>on a side note: each time I run the <code>RegOpenKeyEx</code> the key value is different, is that ok?</p>
  
  <p>2) <strong>with regasm</strong></p>
  
  <p>by using <code>regasm.exe</code> with the <code>/regfile</code> flag, and then replacing in the generated <code>.reg</code> file all <code>HKEY_CLASSES_ROOT</code> occurences with <code>HKEY_CURRENT_USER/Software/Classes</code></p>
  
  <p>this I think should work, but how do I unregister such assembly when I wan't to uninstall my Outlook AddIn?</p>
  
  <p>as I see I can't make it in the same way as register because:</p>
  
  <p><code>var openKeyresult = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Classes", 0, (int)RegistrySecurity.KEY_WOW64_64KEY, out key);</code></p>