1
    public static RegistryKey WritableRegistryRoot
    {
        get
        {
            return Registry.LocalMachine.OpenSubKey(@"SOFTWARE\SubFolder1\SubFolder2", true);
        }
    }

When I run the application I got this error

BlockquoteAn exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll.

But when I run the application as Administrator it works.

When I Change the LocalMachine to CurrentUser my Code works. I have decided to use LocalMachine so that I can use the save data in the registry even if I change my Authentication Login.

If there is other way to access LocalMachine Registry without running my application as administrator?

Noriel
  • 218
  • 1
  • 7
  • 1
    No, writing to LocalMachine requires administrator access. Logically it doesn't make sense to let an unprivileged user modify keys that affect all users. – Rotem Jan 10 '18 at 09:22

1 Answers1

0

You can't. This is intentional on Microsofts part. HKLM (LocalMachine) is restricted, as it affects all logins.

If you need configuration that is shared across windows users you will need to use an alternative unfortunately. Based on the information available, you are trying to use the wrong data storage method anyway.

Maybe if you provide a little more info we could suggest an appropriate data store for what you want.

KeithN
  • 414
  • 1
  • 6
  • 7