title: Not able to create a Registry key in Hkey_Local_Machine from Excel with UAC on
body: <p>I have an excel application(this application is like a product to our company) for which i have created licensing process using Excel &amp; VBA. When the user registers the application using a product key, an entry will be created in Registry and the same will be validated each time the application gets opened. I used the win-API function and VBA to create the key as shown below.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Result = RegCreateKeyEx(HKey:=HKLM, lpSubKey:=SubKeyName, Reserved:=0&amp;, lpClass:=vbNullString, _
                  dwOptions:=REG_OPTION_NON_VOLATILE, samDesired:=KEY_ALL_ACCESS, _
                  lpSecurityAttributes:=SecAttrib, phkResult:=HKey, lpdwDisposition:=Disposition)
  </code></pre>
  
  <p>This product licensing should work for all the users in the local machine. So i am saving the product key in the Registry under HKey_Local_Machine. But with UAC on, i am not able to read from/write to Registry though the user has admin privileges. I always get the error code 5(access denied). Read/write to HKey_Current_User works fine though, but this is not an option in my case as the product registration has to work for all the users on local machine. If i lower the UAC to Never_Notify_Me then read/write to HKLM works fine.</p>
  
  <p>what i tried:</p>
  
  <ol>
  <li><p>I tried to run excel application as an administrator(Excel->Properties->Run this program as administrator). Read/write to Registry HKLM works, but i am not able to open excel application if excel is not already open, meaning by double clicking on the application. Got the error "There was a problem sending the command to the program". So clients will not accept this solution.</p></li>
  <li><p>I have created a C# dotnet dll for writing to the registry and added an application manifest to it with the following info to make it UAC aware. </p></li>
  </ol>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;security&gt;
        &lt;requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"&gt;
            &lt;requestedExecutionLevel  level="requireAdministrator" uiAccess="false" /&gt;
        &lt;/requestedPrivileges&gt;
  &lt;/security&gt;
  </code></pre>
  
  <p>This works fine, when i use it as an exe(by default exe runs as an administrator), but the moment i convert it to COM visible dll and add to Excel references and try to create the registry key, it says access denied.</p>
  
  <ol>
  <li>Created a RegistrySecurity Object in C# and gave the read,write privileges as shown below. But same access denied issue comes up.</li>
  </ol>
  
  <pre class="lang-c prettyprint-override"><code>   RegistrySecurity rs = new RegistrySecurity();
      rs.AddAccessRule(new RegistryAccessRule(user, 
          RegistryRights.WriteKey | RegistryRights.ReadKey| RegistryRights.Delete, 
          InheritanceFlags.None, 
          PropagationFlags.None, 
          AccessControlType.Allow));
  </code></pre>
  
  <ol>
  <li>Did google search to see if there is a WIN-API which allows me to read/write to registry by wither lowering the UAC level temporarily or by somehow bypassing it. But no luck here too.</li>
  </ol>
  
  <p>Now can someone please guide me on how i can make my way through this situation. I am looking for a solution using C# dotnet dll or any other work around like solving excel - run as admin issue. 
  -highly appreciate any suggestions..</p>