Change owners of registry key

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all.,
i dlike to change the ownership of registry key (from "Administrators" object to "JohnyCage" object). I wrote folowed piece of code but it doesnt work properly = no errors, no true results. Any guru here who can correct my code?

<div style="color:black; background-color:white
<pre> <span style="color:blue string subkey = <span style="color:#a31515 "Software\Microsoft\Windows\CurrentVersion\WebCheck";
RegistryKey rk = Registry.LocalMachine.OpenSubKey(subkey, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions | RegistryRights.ReadKey);

RegistrySecurity obj_rSecutity = rk.GetAccessControl(AccessControlSections.Access);
System.Security.Principal.IdentityReference newUser = <span style="color:blue new NTAccount(<span style="color:#a31515 "JohnyCage");
obj_rSecutity.SetOwner(newUser);
rk.SetAccessControl(obj_rSecutity);
[/code]

<br/>
<br/>
(for exampl:
<pre><span style="color:blue string subkey = <span style="color:#a31515 "Software\Microsoft\Windows\CurrentVersion\Setup";[/code]
works fine for me)
<br/>
<br/>
<br/>
<br/>

View the full article
 
Back
Top