No navigation frame on the left?  Click here.

Taking ownership

 

The accompanying sample demonstrates how to take ownership of a file or directory.  To succeed, one or more of the following conditions must be satisfied:

bulletyou have WRITE_OWNER access, and you are assigning ownership to yourself, and you are not the administrator account (i.e., your SID is not S-1-5-32-500), or
bulletyou have enabled SeTakeOwnershipPrivilege, and you are assigning ownership to yourself, and you are not the administrator account (i.e., your SID is not S-1-5-32-500), or
bulletyou have enabled SeRestorePrivilege.  In this case, you can assign ownership to any SID that you take a fancy to.

The sample was written using my fksec classes; not counting error handling and reporting, the actual meat of the code consists of three lines: fksec::GetFileSecurity(), fksec::sd::SetOwnerSid(), and fksec::SetFileSecurity().  If you choose to enable privileges, you can add fksec::priv::Enable() to that list.

ownership.cpp, 5 KB