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----
Willy Denoyette [MVP] - 20 Oct 2007 09:21 GMT
> Hi
>
[quoted text clipped - 22 lines]
> }
> // ----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.