@jostlindemann: "Hi folks !
I need to programmatically take ownership of a registry-key as
administrator. To test this , i created a key
HKEY_LOCAL_MACHINE\Software\TestKey and removed all accessrights from this
key using RegEdt32.
Now i tried to set the accessrights by my programm. Since i do not have
rights to this key, i cannot open the key to get a handle for modifying the
rights.
Microsoft wrote in KB-Article 111546:
<
To take ownership of a registry key it is necessary to have a handle to the
key. A handle to the key can be obtained by opening the key with a registry
API (application programming interface) such as RegOpenKeyEx(). If the user
does not have access to the registry key, the open operation will fail and
this will in turn prevent ownership being taken (because a handle to the key
is required to change the key[ASCII 146]s security).
The solution to this problem is to first enable the TakeOwnership privilege
and 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 used
in the following call to take ownership:
RegSetKeySecurity(hKey,OWNER_SECURITY_INFORMATION,
&SecurityDescriptor);
Please note that you will need to initialize the security descriptor being
passed to RegSetKeySecurity() and set the owner field to the new owner SID.
<quote>
But it does not work by program !
Here is my code:
{
HKEY hKey;
SECURITY_INFORMATION si;
PSECURITY_DESCRIPTOR sd;;
DWORD size=1000;
DWORD result;
result=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Testkey",0,WRITE_OWNER
,&hKey);
result=RegGetKeySecurity(hKey,si,sd,&size);
result=RegSetKeySecurity(hKey,si,sd);
}
When trying to RegOpenKeyEx, it fails with result==5 (Access denied) and of
course other subsequent calls to RegGetKeySecurity failed with 6 (Invalid
handle) since hKey is set to NULL.
So what is wrong ? Why does it not work in a way MS told me ?
My system is W2000prof/SP4, MS VC++ 5.0/SP3.
Thanks in advance !
Jost"
    @checkabdoulatmvpsdotorg: "    Like the documentation says, you need to enable the
SE_TAKE_OWNERSHIP_NAME privilege before calling RegOpenKeyEx(). Take a look
at the following link for an example
<url>
Cheers
Check Abdoul [VC++ MVP]
-
news:3fcd9c10$0$265$<email_address>
<quote>
the
the
registry
user
key
privilege
used
SID.
of"
    @jostlindemann: "Thankx!
But unfortunately, tried to look on your recommended example, MSDN-WebSite
says "Sorry, this document is not available".
I would appreciate just a small chunk of code just for the call to set
SeTakeOwnerShip.
Thanks in advance !
Jost
"CheckAbdoul" <fhill@example.net> schrieb im Newsbeitrag
news:%<email_address>
<quote>
look
<url>
this
and
below:
being
(Invalid"
{'source': 'USENET', 'other_information': '{"reply_count": 2, "forum_name": "microsoft.public.vc.mfc.20140611.mbox"}', 'file': 'data/output/usenet-microsoft.public.parquet'}