EDN Admin
Well-known member
I have a registry key whose owner is "Trusted Installer".
Now I know I can take ownership of the key manually by using registry editor by doing these steps:
1. Right-click the key - Click Permissions - Click Advanced
2. Click Owner Tab, Click your user name and check the box "Replace owner on subcontainers and objects", Click Apply - Click OK.
3. Click Administrators under Group or user name, check Allow Full Control. Then Click Apply - Click OK.
Now my question is, How can I take ownership of the registry key programmatically?
If I am able to take ownership of a registry key programmatically, then my problem is solved. Please help.
Ive tried doing this:
<div style="color:Black;background-color:White; <pre>
RegistrySecurity rs = <span style="color:Blue; new RegistrySecurity();<br/><br/> rs.AddAccessRule(<span style="color:Blue; new RegistryAccessRule(user,<br/> RegistryRights.ReadKey | RegistryRights.Delete,<br/> InheritanceFlags.None,<br/> PropagationFlags.None,<br/> AccessControlType.Allow));<br/><br/> rs.AddAccessRule(<span style="color:Blue; new RegistryAccessRule(user,<br/> RegistryRights.WriteKey | RegistryRights.ChangePermissions,<br/> InheritanceFlags.None,<br/> PropagationFlags.None,<br/> AccessControlType.Allow));<br/><br/>RegistryKey RK = Registry.ClassesRoot.OpenSubKey(<span style="color:#A31515; "<somekey>", <span style="color:Blue; true);<br/>RK.SetAccessControl(rs);<br/>
[/code]
<br/>
but an error message that says that "Requested registry access is not allowed" and it occurs on this line:
<div style="color:Black;background-color:White; <pre>
RegistryKey RK = Registry.ClassesRoot.OpenSubKey(<span style="color:#A31515; "<somekey>", <span style="color:Blue; true);<br/>
[/code]
I am also running Visual Studio as Administrator.
Again, If you know how to programmatically take ownership of a registry key, then you have solved my problem.
View the full article
Now I know I can take ownership of the key manually by using registry editor by doing these steps:
1. Right-click the key - Click Permissions - Click Advanced
2. Click Owner Tab, Click your user name and check the box "Replace owner on subcontainers and objects", Click Apply - Click OK.
3. Click Administrators under Group or user name, check Allow Full Control. Then Click Apply - Click OK.
Now my question is, How can I take ownership of the registry key programmatically?
If I am able to take ownership of a registry key programmatically, then my problem is solved. Please help.
Ive tried doing this:
<div style="color:Black;background-color:White; <pre>
RegistrySecurity rs = <span style="color:Blue; new RegistrySecurity();<br/><br/> rs.AddAccessRule(<span style="color:Blue; new RegistryAccessRule(user,<br/> RegistryRights.ReadKey | RegistryRights.Delete,<br/> InheritanceFlags.None,<br/> PropagationFlags.None,<br/> AccessControlType.Allow));<br/><br/> rs.AddAccessRule(<span style="color:Blue; new RegistryAccessRule(user,<br/> RegistryRights.WriteKey | RegistryRights.ChangePermissions,<br/> InheritanceFlags.None,<br/> PropagationFlags.None,<br/> AccessControlType.Allow));<br/><br/>RegistryKey RK = Registry.ClassesRoot.OpenSubKey(<span style="color:#A31515; "<somekey>", <span style="color:Blue; true);<br/>RK.SetAccessControl(rs);<br/>
[/code]
<br/>
but an error message that says that "Requested registry access is not allowed" and it occurs on this line:
<div style="color:Black;background-color:White; <pre>
RegistryKey RK = Registry.ClassesRoot.OpenSubKey(<span style="color:#A31515; "<somekey>", <span style="color:Blue; true);<br/>
[/code]
I am also running Visual Studio as Administrator.
Again, If you know how to programmatically take ownership of a registry key, then you have solved my problem.
View the full article