Buffer_z Buffer_z - 1 year ago 167
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");

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download