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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top