0

I'm trying to use SetValue to change a key in HKEY_LOCAL_MACHINE, but i'm getting unauthorized "Requested registry access is not allowed" exception although i changed the manifest to run application as administrator, I tried baseKey.OpenSubKey(_path, true) also and it didn't work,

Am i doing something wrong?

 public void RevertToInitial(List<string> changed)
    {
        using (var sub = Registry.LocalMachine.OpenSubKey(_path, true))
        {
            foreach (var key in changed)
            {
                try
                {
                    var initial = _initalValues[key];
                    //Registry.SetValue($@"HKEY_LOCAL_MACHINE\{_path}", key, initial);
                    sub.SetValue(key, initial, RegistryValueKind.Binary);
                    //var change = baseKey.GetValue(key);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

        }
    }

Update: the application is x64, when i change to x86 i don't get the exception but it doesn't actually changes the key. Update: tried to use pInvoke instead, same issue, access denied.

atikot
  • 4,761
  • 4
  • 26
  • 34
  • 1
    duplicate: https://stackoverflow.com/questions/7202752/cannot-write-to-the-registry-key – jazb Oct 13 '18 at 13:39
  • 1
    yeah well the solution there is to add writeable flag, as i wrote I tried baseKey.OpenSubKey(_path, true) also and it didn't work... so the solution there doesn't works. i saw it already.. – atikot Oct 13 '18 at 13:44
  • What about the permissions for the key ? Does the administrator user role have full contol over the key and potentially its parents ? – Kianii Oct 15 '18 at 11:40

0 Answers0