Search code examples
c#registry

Registry.LocalMachine.OpenSubKey() returns null


I get a null back from this attempt to access the Windows Registry:

using (RegistryKey registry = Registry.LocalMachine.OpenSubKey(keyPath))

keyPath is SOFTWARE\\TestKey

The key is in the registry, so why is it not finding it under the Local Machine hive?


Solution

  • In your comment to Dana you said you gave the ASP.NET account access. However, did you verify that that is the account that the site in running under? Impersonate and the anonymous access user can be easy to overlook.

    UNTESTED CODE:

    Response.Clear();  
    Response.Write(Environment.UserDomainName + "\\" + Environment.UserName);  
    Response.End();