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:
- Right-click the key - Click Permissions - Click Advanced
- Click Owner Tab, Click your user name and check the box "Replace owner on subcontainers and objects", Click Apply - Click OK.
- 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.
I've tried doing this:
string user = Environment.UserDomainName + "\" + Environment.UserName;
RegistrySecurity rs = new RegistrySecurity();
RegistryRights.ReadKey | RegistryRights.Delete,
RegistryRights.WriteKey | RegistryRights.ChangePermissions,
RegistryKey RK = Registry.ClassesRoot.OpenSubKey("<somekey>", true);
but an error message that says that "Requested registry access is not allowed" and it occurs on this line:
RegistryKey RK = Registry.ClassesRoot.OpenSubKey("<somekey>", true);<br/>
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.
I understand you can also use these functions: RegOpenKeyEx and RegSetKeySecurity to Take Ownership of a registry key but I don't know how to use them. Can someone give a sample with an explanation on how to use them.
I have seen these sites before:
But I still don't understand how I can use them in C#.
Thanks in advance.