I have tried several ways to get MoveFileEx working with the DELAY_UNTIL_REBOOT flag without success. The FileRenameOperations key in the registry also shows that the method did not execute properly. What could be the cause?
I call my MoveFileEx function like this:
MoveFileEx(localFile, oldFile, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
My WINAPI code is as follows:
[DllImport("kernel32.dll", EntryPoint = "MoveFileEx")]
internal static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags);
internal enum MoveFileFlags
{
MOVEFILE_REPLACE_EXISTING = 1,
MOVEFILE_COPY_ALLOWED = 2,
MOVEFILE_DELAY_UNTIL_REBOOT = 4,
MOVEFILE_WRITE_THROUGH = 8
}
This application is run under admin account. Could this be because I’m using 4 instead of 0x4 or is it some 64bit problem? Thanks!
EDIT: The Operation returns false and error code of 3.
Error code 3 is
ERROR_PATH_NOT_FOUND. It seems that you made a simple mistake in your file names: one of the directories in one of your file names does not exist.In a comment, you state that the call that fails is of the form:
This will certainly fail. What you are trying to do is pass
NULLas the destination filename in order to delete the file. But you are not passingNULL, you are passing the empty string. In order to passNULLto the native API, call it like this:I would make sure that you include
SetLastError = truein your pinvoke so that you can diagnose errors.