views:

83

answers:

1

Assume we have c:\DirA that can be read by User1 only, and c:\DirB that can be written by User2 only. Both credentials are know.

How can I copy files from DirA to DirB directly?

+1  A: 

Assuming the process is run in the context of the first user, run LogonUser to obtain a security token for the second user. Spawn a thread and call ImpersonateLoggedOnUser, passing the token as a parameter. The second thread will have access to DirB. Read data in the first thread, pass them to the second and write them from there.

If the user you're running under has backup or restore privileges, the easier way would be to activate them with OpenProcessToken followed by AdjustTokenPrivileges.

avakar