I need to copy and move files and keep all the file attributes
including the NT security attributes. Can anyone tell me how
to do this?
TIA
Mark Williams
You've got a couple of possibilities. The most obvious is to copy
the file (e.g. with CopyFile) and then copy the security attributes
with GetFileSecurity and SetFileSecurity (after enabling the
SE_SECURITY_NAME privilege).
A less obvious way would be to call BackupRead to read the old file,
and then use BackupWrite to write the new one. These are supposed to
copy the entire file, including security attributes, secondary file
streams, and so on.
--
Later,
Jerry.
The Universe is a figment of its own imagination.
On Fri, 3 Aug 2001 05:00:27 -0600, Jerry Coffin <jco...@taeus.com>
wrote:
>You've got a couple of possibilities. The most obvious is to copy
>the file (e.g. with CopyFile) and then copy the security attributes
>with GetFileSecurity and SetFileSecurity (after enabling the
>SE_SECURITY_NAME privilege).
How can the SE_SECURITY_NAME privilege be set?
TIA
Basically you OpenProcessToken then AdjustTokenPrivileges.
Check SHFileOperation() on MSDN.
You can copy/move more than one file by using this function.
You just have to set appropriate buffers and flags to do it right.
I think it copies security attributes by default, but there's a flag to disable it.
Regards,
Michael
Note that there are some problems with BackupWrite in W2K, see
http://support.microsoft.com/support/kb/articles/Q271/3/98.ASP and
http://support.microsoft.com/support/kb/articles/Q259/3/93.ASP . I'm
also not sure that BackupRead/BackupWrite will process encrypted files
in W2K. See http://www.collakesoftware.com/files/efsraw10.zip for an
example on how to perform a "raw" copy of encrypted files.
Ralf.