A.B.
A.B.

Reputation: 2470

C# Registry Permission

i want to be able to modify all subkeys of HKEY_CLASSES_ROOT.

I have the following manifest code:

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

I have the following assembly code:

[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CLASSES_ROOT")]

This works:

 Registry.ClassesRoot.CreateSubKey("._test");

But this fails (unless the key is programmatically created):

 RegistryKey key = Registry.ClassesRoot.OpenSubKey("any_key");
 key.CreateSubKey("._test");

The user decides which key is selected, therefore i can't write down:

[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CLASSES_ROOT/desired_subkey")]

since the desired_subkey is dynamically chosen during program execution.

So any ideas?

Upvotes: 0

Views: 1802

Answers (1)

shf301
shf301

Reputation: 31404

Registry.OpenKey(string) opens the key readonly. You need to use one of the overloads that will give you write access.

Upvotes: 1

Related Questions