MoveFileEx with deleting MOVEFILE_DELAY_UNTIL_REBOOT rather than moving

I have an automatic update system that replaces my existing program files upon reboot. (Suffice it to say that this is a very complex program with many drivers, services and user-level modules. There is no other way. Believe me.)

The MoveFileEx function is used with MOVEFILE_DELAY_UNTIL_REBOOT to set this file replacement. I find that this is working fine. However, if the source and target files are on different drives, the target is deleted, but the source does not move. As a result, when the user installs the software on a drive other than the system partition, the update deletes the product file rather than updating it.

Now I see in the documentation for MoveFileEx that MOVEFILE_COPY_ALLOWED should be used when moving a file from one volume to another. But he also says that the flag cannot be used with MOVEFILE_DELAY_UNTIL_REBOOT.

Q: How can I move a file on reboot, overwriting an existing file when the source and target are not on the same volume?

+4
source share
1 answer

Why don't you just copy the files to the disk where the user installed your program?

As far as I can see, there is no direct way to do what you want to rely on only this function.

Finding a writable location on the same drive may be a problem for Vista, but you mentioned that you have services โ€” if they work with LocalSystem licenses, they need to write new files.

Another simple update mechanism that I used (does not work for drivers) was to have a special update program - kill / finish everything, so that the update program does its job and starts everything again.

+2
source

Source: https://habr.com/ru/post/1286426/


All Articles