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.