EDN Admin
Well-known member
Hi,
Does any one know how to take ownership of a registry entry in Windows 7 programmatically? I have found related threads in this forum and found some line of code that point in the right direction to achieve this. However, there is still missing some logic
to allow access to the registry key to change ownership.
In my case I want to take ownership of the following registry key in Windows 7.
<span>
HKEY_CLASSES_ROOT\CLSID\{083863F1-70DE-11D0-BD40-00A0C911CE86}\Instance\{E1F1A0B8-BEEE-490D-BA7C-066C40B5E2B9}
<span>
When using the code suggested to take ownership being an Administrator I use the following code.
<span>
<span>
string regstr=@"CLSID{083863F1-70DE-11D0-BD40-00A0C911CE86}Instance{E1F1A0B8-BEEE-490D-BA7C-066C40B5E2B9}";
using (RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(regstr, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions))
<span> {
<span> RegistrySecurity rs = new RegistrySecurity();
<span> rs.SetGroup(new NTAccount("Administrators"));
<span> rs.SetOwner(new NTAccount("Administrators"));
<span> rs.SetAccessRuleProtection(false, false);
<span> regKey.SetAccessControl(rs);
<span> }
When I try to execute this logic, I get the following error message on the "OpenSubKey" Method, "Requested registry access is not allowed."
See in Windows 7 there an account called "TrustedInstaller". This object has full access to the registry entry I am interested in modifying. Also, I am an administrator of my developing station. SO there is no issue of not being an Administrator.
If I use "RegEdit.exe", I can get to the subkey and takeowership and give it to the administrator. So there exist a way to achieve the same in code. I have a feeling something simple is missing but the missing logic is a mystery.
Does anyone know now to resolve this issue?
Thanks for your help.
View the full article
Does any one know how to take ownership of a registry entry in Windows 7 programmatically? I have found related threads in this forum and found some line of code that point in the right direction to achieve this. However, there is still missing some logic
to allow access to the registry key to change ownership.
In my case I want to take ownership of the following registry key in Windows 7.
<span>
HKEY_CLASSES_ROOT\CLSID\{083863F1-70DE-11D0-BD40-00A0C911CE86}\Instance\{E1F1A0B8-BEEE-490D-BA7C-066C40B5E2B9}
<span>
When using the code suggested to take ownership being an Administrator I use the following code.
<span>
<span>
string regstr=@"CLSID{083863F1-70DE-11D0-BD40-00A0C911CE86}Instance{E1F1A0B8-BEEE-490D-BA7C-066C40B5E2B9}";
using (RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(regstr, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions))
<span> {
<span> RegistrySecurity rs = new RegistrySecurity();
<span> rs.SetGroup(new NTAccount("Administrators"));
<span> rs.SetOwner(new NTAccount("Administrators"));
<span> rs.SetAccessRuleProtection(false, false);
<span> regKey.SetAccessControl(rs);
<span> }
When I try to execute this logic, I get the following error message on the "OpenSubKey" Method, "Requested registry access is not allowed."
See in Windows 7 there an account called "TrustedInstaller". This object has full access to the registry entry I am interested in modifying. Also, I am an administrator of my developing station. SO there is no issue of not being an Administrator.
If I use "RegEdit.exe", I can get to the subkey and takeowership and give it to the administrator. So there exist a way to achieve the same in code. I have a feeling something simple is missing but the missing logic is a mystery.
Does anyone know now to resolve this issue?
Thanks for your help.
View the full article