Changing registry permission
I want to change th开发者_StackOverflow中文版e permission of a registry key, and I want to set it as a read only. How can I do this?
I tried this way, but it doesn't change anything:
RegistryPermission rp = new RegistryPermission(
RegistryPermissionAccess.Read,
"HKEY_LOCAL_MACHINE\\SOFTWARE\\paci_1\\identity\\ASPNET_SETREG"
);
rp.AddPathList(
RegistryPermissionAccess.Read,
"HKEY_LOCAL_MACHINE\\SOFTWARE\\paci_1\\identity\\ASPNET_SETREG"
);
Also, how can I do it for a user or administrator or owner etc?
I think the class you want is RegistrySecurity. It's documented here.
It should look something like this:
using(RegistryKey rk =
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\paci_1\identity\ASPNET_SETREG") )
{
string gname = Environment.UserDomainName + @"\" + Environment.UserName;
RegistrySecurity rs = new RegistrySecurity();
rs.AddAccessRule(new RegistryAccessRule(gname, RegistryRights.ReadKey, AccessControlType.Allow));
rk.SetAccessControl(rs);
}
Of course, you would replace gname
with the domain-qualified username of your choice.
精彩评论