How could i change permission on registrykey

  • Thread starter Thread starter Judith Schmidt
  • Start date Start date
J

Judith Schmidt

Hi

i need a way to set permission on a registry key where i have got not rights
to open it. But i am the owner (administrator).

The following code fails on OpenSubKey() with
System.Security.SecurityException: Requested registry access is not allowed

// ----start----
SetPermissions(){
String^ user = Environment::UserDomainName + "\\testuser";
RegistryKey^ openedKey;
RegistrySecurity regSecurity = gcnew RegistrySecurity();
regSecurity->AddAccessRule(gcnew RegistryAccessRule(user,
RegistryRights::ReadKey,
InheritanceFlags::ContainerInherit | InheritanceFlags::ObjectInherit,
PropagationFlags::InheritOnly,
AccessControlType::Allow));
regSecurity->SetAccessRuleProtection(false,true);
openedKey =
Registry::Users->OpenSubKey("S-1-5-18\\software\\testkey",true);
openedKey->SetAccessControl(regSecurity);
return 0;
}
// ----end----
 
Judith Schmidt said:
Hi

i need a way to set permission on a registry key where i have got not
rights to open it. But i am the owner (administrator).

The following code fails on OpenSubKey() with
System.Security.SecurityException: Requested registry access is not
allowed

// ----start----
SetPermissions(){
String^ user = Environment::UserDomainName + "\\testuser";
RegistryKey^ openedKey;
RegistrySecurity regSecurity = gcnew RegistrySecurity();
regSecurity->AddAccessRule(gcnew RegistryAccessRule(user,
RegistryRights::ReadKey,
InheritanceFlags::ContainerInherit | InheritanceFlags::ObjectInherit,
PropagationFlags::InheritOnly,
AccessControlType::Allow));
regSecurity->SetAccessRuleProtection(false,true);
openedKey =
Registry::Users->OpenSubKey("S-1-5-18\\software\\testkey",true);
openedKey->SetAccessControl(regSecurity);
return 0;
}
// ----end----


That means you don't run as "administrator". Be aware that "administrators"
run as normal users on Vista! If you need to perform administrative tasks
you'll have to run with elevated privileges.

Willy.
 
Back
Top