I think I've found a bug in MoveFileEx which affects an extremely specific condition when running under a 32bit process on a 64bit computer.
Calling with dwFlags MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING.
The problem is that you can't move a file in System32 - and wait, this probably isn't what you think it is.
I've covered all of the basis - file permissions (write etc. on destination, delete on source), AllowPendingRenames, etc. etc.
The function returns success, and the PendingFileRenameOperations registry key is set almost correctly.
But here's the problem - when I make a call from a 64bit application, everything works fine and the replacement goes through perfectly over the reboot - this suggests to me that my permissions, AllowPendingRenames, etc. setup are correct.
However, I would get a silent failure over the reboot when running from a 32bit application on a 64bit computer, so I started to look into why this might be.
It turns out that MoveFileEx with this setup from a WOW64 application redirects System32 --> SysWOW64. Nothing unexpected there, perfect behavior infact. So what if I want to access System32 itself? Well, I use Sysnative. Well, here's the problem. MoveFileEx doesn't convert Sysnative --> System32, (and smss.exe won't accept Sysnative over the reboot from what I can see) and consequently I am a bit stuck for accessing System32.
Must I use Wow64DisableWow64FsRedirection/Wow64RevertWow64FsRedirection? Just seems a bit weird that MoveFileEx redirects System32 --> SysWOW64, but not Sysnative --> System32. I would consider this a bug. Just wondering whether I've perhaps overlook something.
But...if I manually tweak the registry from Sysnative --> System32, and replacement goes perfectly. So there can't be anything wrong with the setup, just how I'm calling the function, or a bug, or something undocumented.
This is such a specific case with workarounds that it really doesn't matter, more a curiosity (and after all, worst case scenario I could manually set the registry key myself).
Richard
EDIT: Can now confirm for sure Wow64DisableWow64FsRedirection/Wow64RevertWow64FsRedirection works as expected. That is probably the best workaround, but it still feels a little buggy.
Calling with dwFlags MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING.
The problem is that you can't move a file in System32 - and wait, this probably isn't what you think it is.
I've covered all of the basis - file permissions (write etc. on destination, delete on source), AllowPendingRenames, etc. etc.
The function returns success, and the PendingFileRenameOperations registry key is set almost correctly.
But here's the problem - when I make a call from a 64bit application, everything works fine and the replacement goes through perfectly over the reboot - this suggests to me that my permissions, AllowPendingRenames, etc. setup are correct.
However, I would get a silent failure over the reboot when running from a 32bit application on a 64bit computer, so I started to look into why this might be.
It turns out that MoveFileEx with this setup from a WOW64 application redirects System32 --> SysWOW64. Nothing unexpected there, perfect behavior infact. So what if I want to access System32 itself? Well, I use Sysnative. Well, here's the problem. MoveFileEx doesn't convert Sysnative --> System32, (and smss.exe won't accept Sysnative over the reboot from what I can see) and consequently I am a bit stuck for accessing System32.
Must I use Wow64DisableWow64FsRedirection/Wow64RevertWow64FsRedirection? Just seems a bit weird that MoveFileEx redirects System32 --> SysWOW64, but not Sysnative --> System32. I would consider this a bug. Just wondering whether I've perhaps overlook something.
But...if I manually tweak the registry from Sysnative --> System32, and replacement goes perfectly. So there can't be anything wrong with the setup, just how I'm calling the function, or a bug, or something undocumented.
This is such a specific case with workarounds that it really doesn't matter, more a curiosity (and after all, worst case scenario I could manually set the registry key myself).
Richard
EDIT: Can now confirm for sure Wow64DisableWow64FsRedirection/Wow64RevertWow64FsRedirection works as expected. That is probably the best workaround, but it still feels a little buggy.
Last edited: