Search code examples
c#.netwindowsregistryregistry-virtualization

How reliable is HKEY_USERS if I know the user's SID?


I'm attempting to access registry values (written by another program) that should be readily available via the HKEY_CURRENT_USER registry base key when accessed from the logged on user's context. Unfortunately, I'm accessing this information from a service, therefore from what I've gathered, I have two options:

  • Impersonate the logged on user for every piece of code that accesses the registry and access the registry using the HKEY_CURRENT_USER base key via HKEY_CURRENT_USER/SOFTWARE/Company/Product...
  • Get the logged on user's SID and access the registry using the HKEY_USERS base key via HKEY_USERS/{SID}/SOFTWARE/Company/Product...

I'd very much like to use the second solution, as it is far less complicated for the large codebase I'm working with. I've only recently learned of Registry Virtualization and the problems it can cause, so I'd like to verify that my solutions above will work and ask if there are any other solutions available to solve my problem.

Thanks for any knowledge you can offer on the subject, or articles you can point me towards that I may have been unable to find.


Solution

  • Went with my second solution, seems to work just fine for multiple OS versions in multiple scenarios. After more research and little input from others here, not sure there are any other viable solutions available for this problem.

    Get the logged on user's SID and access the registry using the HKEY_USERS base key via HKEY_USERS/{SID}/SOFTWARE/Company/Product...