Configuring Registry Access

Installing system wide settings under HKEY_LOCAL_MACHINE can be a problem if the user running the application has to modify the registry settings and is only a limited user (non-admin).

The following code shows how a particular registry key can be configured to allow access to other permission groups.

//Create an object for the registry key in question
RegistryKey key = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\SOFTWARE\MyKey", RegistryKeyPermissionCheck.ReadWriteSubTree);

RegistrySecurity regSec = new RegistrySecurity();

//Add the required access rules for the key
regSec.AddAccessRule(new RegistryAccessRule("Users", RegistryRights.ReadKey | RegistryRights.WriteKey,
InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));

//Set the new rules for the key

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s