views:

273

answers:

1

I have an automatic update system that replaces my existing program files on reboot. (Suffice to say, it's a very complicated program with many drivers, services, and user level modules. There really is no other way. Trust me.)

The function MoveFileEx is used with MOVEFILE_DELAY_UNTIL_REBOOT to setup this file replacement. I'm finding that it works just fine, normally. However, if the source and target files are on different drives, the target is deleted but the source is not moved. The result is that when the user installs the software on a drive different from the system partition, an update deletes the product file rather than update them.

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 it also says that 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 the target are not on the same volume?

+2  A: 

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

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

Finding writable location on the same drive might be a problem on Vista, but you mention you have services - if they run with LocalSystem privilleges have them write the new files.

One other simple update mechanism that I have used ( not working for drivers though) is to have dedicated update program - kill/end everything, let the update program do its work and start everything up again.

devdimi
+1 put the files in a subdir of the app directory pending reboot
sean e
Well, after some research, I think the only solution is to do as you've suggested: Make sure the source files are on the same volume before calling MoveFileEx. I guess this isn't too troublesome since the service has the required access. Thanks for the advice.
Charles