INFO: Taking Ownership of Registry Keys

This article was previously published under Q111546
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
To take ownership of a registry key it is necessary to have a handle to thekey. A handle to the key can be obtained by opening the key with a registryAPI (application programming interface) such as RegOpenKeyEx(). If the userdoes not have access to the registry key, the open operation will fail andthis will in turn prevent ownership being taken (because a handle to thekey is required to change the key[ASCII 146]s security).

The solution to this problem is to first enable the TakeOwnership privilegeand then to open the registry key with WRITE_OWNER access as shown below:
   RegOpenKeyEx(HKEY_CLASSES_ROOT,"Testkey",0,WRITE_OWNER,&hKey);				
This function call will provide a handle to the registry, which can be usedin the following call to take ownership:
RegSetKeySecurity(hKey,OWNER_SECURITY_INFORMATION, &SecurityDescriptor);				
Please note that you will need to initialize the security descriptor beingpassed to RegSetKeySecurity() and set the owner field to the new owner SID.

Taking ownership of a registry key is not a common operation. It istypically an operation that an administrator would use as a last resort togain access to a registry key.
Properties

Article ID: 111546 - Last Review: 02/28/2014 07:54:23 - Revision: 4.1

  • Microsoft Win32 Application Programming Interface
  • kbnosurvey kbarchive kbinfo kbregistry kbapi kbkernbase kbsecurity KB111546
Feedback