title: RegSetValueEx returns "Access is denied", even though regedit allows the same user to edit this value
body: <p>Our VB6 legacy application calls RegSetValueEx to set a registry value. This registry value can be easily set using regedit. However, when our application tries to set it, RegSetValueEx returns 5 - Access Is Denied. </p>
  
  <p>We use the same code to write to other registry keys and everything works fine. Also, the user is a local administrator.</p>
  
  <p>The key is opened using KEY_ALL_ACCESS, but I tried using (KEY_READ or KEY_WRITE) and that didn't work either.</p>
  
  <pre><code>Private Const READ_CONTROL = &amp;H20000
  Private Const KEY_QUERY_VALUE = &amp;H1
  Private Const KEY_SET_VALUE = &amp;H2
  Private Const KEY_CREATE_SUB_KEY = &amp;H4
  Private Const KEY_ENUMERATE_SUB_KEYS = &amp;H8
  Private Const KEY_NOTIFY = &amp;H10
  Private Const SYNCHRONIZE = &amp;H100000
  Private Const STANDARD_RIGHTS_ALL = &amp;H1F0000
  Private Const STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)
  Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
  Private Const STANDARD_RIGHTS_REQUIRED = &amp;HF0000
  Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
  Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or     KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
  
  Private Const KEY_CREATE_LINK = &amp;H20
  Private Const KEY_ALL_ACCESS = &amp;H3F
  
  Private Const REG_OPTION_NON_VOLATILE = 0&amp;
  
  Private Const HKEY_LOCAL_MACHINE = &amp;H80000002
  
  Dim hKey As Long
  Dim e As Long
  Dim lCreate As Long
  Dim tSA As SECURITY_ATTRIBUTES
  Dim keyOpened   As Boolean
  
  e = RegCreateKeyEx(HKEY_LOCAL_MACHINE , "SOFTWARE\Classes\Word.Document.8", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, tSA, hKey, lCreate)
  
  e = RegSetValueExLong(hKey, "BrowerFlags", 0&amp;, REG_DWORD, newValue, 4)
  </code></pre>