Dev Center - Desktop > Windows Desktop Development Forums > Windows Desktop SDK > CopyFile() (and others) not copying entire file properly

Answered CopyFile() (and others) not copying entire file properly

  • Saturday, February 11, 2012 3:34 PM
     
     

    I'm using CopyFile() in a Windows Installer deferred custom action running in SYSTEM context to make backups of files in case rollback is required (seemingly a simple operation).  I'm finding in some files, the file is not properly copied.  The files that are giving me problems are encrypted SQL MDF/LDF databases that are encrypted by a third party application.  Only the file itself is encrypted.  No file system level encryption is present.

    Due to their contents, it is difficult to figure out exactly what is being copied but I know for certain that the file is truncated to the sector size.  The original file is slightly larger than the copy.  I've tried CopyFileEx() and SHFileOperation() all with the same results.

    If I create a small console application (which does not run in SYSTEM context) to perform the exact same copy I'm duing in the custom action, the copy operation works as expected.  Copy also functions as expected if I copy the file using Windows Explorer.  Only these APIs in the custom action seem to give incorrect results. 

    The system I'm currently using in Windows 7 x86 w/o SP1 to test this installer.  I've not investigated others yet.  I've turned off Windows Defender.

    Any idea what could be turning this simple project into something that has taken me several days now?

Answers

  • Sunday, February 12, 2012 4:15 AM
     
     Answered

    I figured it out.  It appears that after certain actions are taken with the encryption software, that CopyFile() will cause the copy to be unencrypted.  If you don't perform these actions, the copied file is not unencrypted.  That was leading to the confusion because the action I took I did not expect this to occur.

    I didn't think that CopyFile() could have such a major flaw.

    • Marked As Answer by simdoc Sunday, February 12, 2012 4:15 AM
    •