Buffer_z Buffer_z - 2 months ago 25
C# Question

c# Registry Unable to Create a SubKey

I couldn't create a subkey under the following Path :

Registry.CurrentUser + @"\Software\";


I tried that using the following code :

RegistryKey Key = Registry.CurrentUser.OpenSubKey("SOFTWARE").CreateSubKey("MyKey");
Key.SetValue("Check","Yes");


Cannot write :
Cannot write to the registry key.


I also tried to open the application with the admin privileges , but it still display the same error.

Please note that i can create subkeys in Registry.CurrentUser without admin privileges ,And I Have the Permission Read/Full Control on the Both Paths (Current User and SOFTWARE)

Answer

It's because according to MSDN, OpenSubKey retrieves a subkey as read-only. Instead, try to use OpenSubKey(name, true).