I’m running a C# service running under the System account trying to access the following registry key:
\CLSID{8E7FE1EC-79FA-43DF-9452-B71542599B3C}\InProcServer32\
The Key exists and I can access it during unit tests fine (unit tests run under the current user). The service can Access other keys in the Classes root but when I try to access anything in the CLSID subkey it fails.
var regPermission = new RegistryPermission(RegistryPermissionAccess.AllAccess,
@"HKEY_CLASSES_ROOT\" + regPath);
regPermission.Demand();
using (var regKey = rootKey.OpenSubKey(regPath))
{
if (regKey != null)
{
string defaultValue = (string)regKey.GetValue("");
{
return defaultValue;
}
}
else
{
Logger.Info("Unable to open " + regPath);
}
}
For anything beneath CLSID my code is returning ‘Unable to open’ + regPath..
Any tips as to why would be greatly appreciated
This is happening because HKEY_CLASSES_ROOT is simply a pointer to
HKEY_CURRENT_USER\Software\Classesand when noboy is logged in, well… then it won’t exist. The real hive can be found underHKEY_USERS\{user_guid | .DEFAULT}\Software\Classes, so unless you know the user’s GUID, you’ll have to use .DEFAULT.You might try using
HKEY_LOCAL_MACHINE\Software\Classesinstead.