After a copy of a file I would like to change the owner of the copied file to the owner of the original file. I've tried many (many) things but I'm getting "access denied" as LastErrorStr. When I start my application As Administrator then I get "This security ID may not be assigned as the owner of this object."

Looks ok to me. Not sure what's going on there. You could debug madSecurity.pas by copying it (and mad.inc) into your project folder. Basically madSecurity is just a wrapper around the win32 API. So in the end either the wrapper must do something wrong, or the underlying win32 APIs doesn't play ball.

The SecurityInfo parameter must include the OWNER_SECURITY_INFORMATION flag. To set the owner, the caller must have WRITE_OWNER access to the object or have the SE_TAKE_OWNERSHIP_NAME privilege enabled.

And of course you can only enable privileges that you already have but which are just not enabled yet. If your user account doesn't have a specific privilege *at all* (not even in disabled state), then the user simply can't do this. In that case you need to use a different user.

My tool can be used as application or as service. With the service version I don't have to add any Administrator tricks. Even the default Logon As user of the service (= Local System Account) is allowed to change the owner of the copied file. Strange ..