C# Create Values in Registry Local Machine
c#, registry
Solution
Non-admin and unelevated admin users don't have rights to modify the HKEY_LOCAL_MACHINE key. Run the program 'as administrator'.
Problem
The following code is not working for me: ``` public bool createRegistry() { if (!registryExists()) { Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\xelo\\"); Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\xelo").SetValue("hostname", (string)hostname, Microsoft.Win32.RegistryValueKind.String); return true; } else { return updateRegistry(); } } ``` Exception: System.UnauthorizedAccessException | "Cannot write to the registry key"