title: Detecting registry virtualization
body: <p>I have a set of C# (v2) apps and I am struggling with registry virtualization in Win7 (and to a lesser extent Vista).</p>
  
  <p>I have a shared registry configuration area that my applications need to access in HKLM\Software\Company...  Prior to Vista, everything was just written to and read from that location as needed.</p>
  
  <p>The code appropriately detected failures to write to that registry key and would fall back appropriately (writing to HKCU instead and notifying the user that the settings they had applied would only affect the current user).</p>
  
  <p>In Vista, registry virtualization broke all of this because the access check we were using for the HKLM write would "succeed" silently and virtualize to HKCR\VirtualStore\Machine... instead.  In this case, the user would think that they had saved machine-wide configuration, but had instead only written to the virtual store.</p>
  
  <p>Sadly, even attempting to enumerate the permissions on the HKLM reg key explicitly returns results indicating that the user has access whether they do or not.</p>
  
  <p>When we added Vista support, the workaround we used was to perform a probe write to HKLM... and then check in HKCR\VirtualStore\Machine... for the same value and note that virtualization had occurred if the value was found.</p>
  
  <p>Win7 seems to have broken this (again) because queries against the explicit virtual location (HKCR) now show merged results from the HKLM location even if the write was not virtualized.</p>
  
  <p>Does anyone have any suggestions for working around this?</p>
  
  <p>Constraints:
   - I need a solution that works without requiring elevation (when I don't have administrator level permissions I will fallback to a per-user configuration in HKCU but I need to be able to detect this case reliably).</p>
  
  <ul>
  <li><p>It needs to work with a v2 C# app (One option I have seen for C++ code is to embed a manifest which disables virtualization for the .exe but I haven't been able to do that in C# V2 see <a href="https://stackoverflow.com/questions/873676/disable-folder-virtualization-in-windows">disable folder virtualization in windows</a>).</p></li>
  <li><p>It needs to work without an "installer" (this precludes the ability to disable virtualization on the registry key that we need ala the REG FLAGS... command).</p></li>
  </ul>