Home All Groups Group Topic Archive Search About

Changing registry permissions without write access.

Author
6 Oct 2006 12:52 PM
hagueb
I'd like to have a registry key for which access is normally denied,
but which my program can alter. I've tried using a deny write
permission but then there seems to be no way to alter it, as if I do
RegistryKey^ currentUser = Registry::CurrentUser;
RegistryKey^ regKey = currentUser->=GetSubKey("key",false);
myRegistrySecurity->AddAccessRule(myRule);
regKey->SetAccessControl(myRegistrySecurity);

I get the error message:
System.UnauthorizedAccessException: Cannot write to the registry key.
   at
System.ThrowHelper.ThrowUnauthorizedAccessException(ExceptionResource
resource)
   at Microsoft.Win32.RegistryKey.SetAccessControl(RegistrySecurity
registrySecurity)
   at main(),

while if I do
RegistryKey^ currentUser = Registry::CurrentUser;
RegistryKey^ regKey = currentUser->=GetSubKey("key",true);
myRegistrySecurity->AddAccessRule(myRule);
regKey->SetAccessControl(myRegistrySecurity);

I get the error message:
System.Security.SecurityException: Requested registr
y access is not allowed.
   at System.ThrowHelper.ThrowSecurityException(ExceptionResource
resource)
   at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean
writable)
   at main()
The Zone of the assembly that failed was:
MyComputer

In both cases Write access is denied, but WriteDAC access is allowed.
Permissions on the key are inherited, which it appears cannot be
altered, so I have to use denied permissions.

I'm using c++ and framework 2.0.

AddThis Social Bookmark Button