Change registry permission

I want to change the permission of a registry key, and I want to set it as read-only. How can i do this?

I tried this way, but nothing changes:

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 this for a user or administrator or owner, etc.

+4
source share
1 answer

I think the class you want is RegistrySecurity. He 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 gname with the username corresponding to the domain of your choice.

+2
source

Source: https://habr.com/ru/post/1344587/


All Articles