Platform SDK: Registry |
You may want to restrict access to specific data in the registry—for example, to sensitive performance data that, by default, is accessible to anyone, including remote users. There are also times when an application must access certain registry keys that its user does not have access to. For these reasons, Windows NT/Windows 2000 assigns a level of security to each registry key.
Note Taking ownership of a registry key is not a common operation. It is typically performed by an administrator as a last resort to gain access to a registry key.
To change this security level for a key under Windows NT/Windows 2000, do the following.
RegOpenKeyEx (HKEY_CLASSES_ROOT, "Testkey", 0, WRITE_OWNER, &hKey);
This function call will return a handle to the registry.
RegSetKeySecurity (hKey, OWNER_SECURITY_INFORMATION, &SecurityDescriptor);
Keep in mind that you need to initialize the SECURITY_DESCRIPTOR structure passed to RegSetKeySecurity as the SecurityDescriptor parameter, and set its owner field to your own owner SID. To obtain your owner SID, call LookupAccountName .