What I need to do is to read an application specific string value from HKLM from a windows service. The registry hive and values were added using a windows form, a tool for modifying configuration values for the windows service. I am not able to read the values from my windows service, “Requested registry access is not allowed”. I am trying to open and read as follows:
rk = Registry.LocalMachine.OpenSubKey(key, RegistryKeyPermissionCheck.ReadSubTree);
if (rk != null)
{
value = rk.GetValue(setting).ToString();
}
Are the app and service running under different credentials? The configuration app may be having registry virtualization applied to it (http://msdn.microsoft.com/en-us/library/aa965884.aspx).
OR there could be a difference between the bitness of the config app and the service and are seeing different views of the registry (http://msdn.microsoft.com/en-us/library/aa384232.aspx).