Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RegistryKey baseKey;
- if (!String.IsNullOrEmpty(remoteName))
- {
- baseKey = RegistryKey.OpenRemoteBaseKey(hive, remoteName, regView);
- }
- else
- {
- baseKey = RegistryKey.OpenBaseKey(hive, regView);
- }
- var key = baseKey.OpenSubKey(keyPath, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl);
- if (key != null)
- {
- RegistrySecurity rs = key.GetAccessControl();
- rs.SetOwner(new NTAccount(domainName, userName));
- if (removeInheretence)
- {
- // Removes Inheretence
- rs.SetAccessRuleProtection(true, false);
- }
- // Gets a list of explicit ACL's And Removes Them
- if (removeExplicitPermissions)
- {
- AuthorizationRuleCollection aclRuleCollection = rs.GetAccessRules(true, false,
- typeof(NTAccount));
- foreach (RegistryAccessRule aclRule in aclRuleCollection)
- {
- rs.RemoveAccessRule(aclRule);
- }
- }
- rs.SetAccessRule(new RegistryAccessRule(new NTAccount(domainName, userName),
- RegistryRights.FullControl, AccessControlType.Allow));
- rs.AddAccessRule(new RegistryAccessRule("System", RegistryRights.FullControl,
- AccessControlType.Allow));
- if (administratorFullControl)
- {
- rs.AddAccessRule(new RegistryAccessRule("Administrators", RegistryRights.FullControl,
- AccessControlType.Allow));
- }
- key.SetAccessControl(rs);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement