Search code examples
c++cwindowspermissionsencrypting-file-system

How to copy a file and inherit Windows EFS?


I have a program where I create a temp file in %USERPROFILE%\AppData\Local\Temp, and I then call rename.c's _wrename() function to effectively move that file to a directory which is encrypted with Windows' EFS. The problem is that this file doesn't inherit that directory's encryption settings. Is there any way to overcome this (I don't want to encrypt the Temp folder, btw)?


Solution

  • I believe you want to use the Win32 functions instead of the C functions. I'm unsure if MoveFileEx will do what you want. CopyFileEx can be used to do this, and it's then possible to delete the original. CopyFileEx even has flags which allow it to fail/not if encryption is not possible at the destination.