If OrigionalFile is open, this works fine:
MoveFileEx(NewFile, OrigionalFile, MOVEFILE_DELAY_UNTIL_REBOOT + MOVEFILE_REPLACE_EXISTING)
But if OrigionalFile is open AND the file properties are set to ReadOnly the above command does not work. How can I replace OrigionalFile under thses conditions?
What Os are you using?
MOVEFILE_DELAY_UNTIL_REBOOT only works on NT...
Also try
Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Because:
MOVEFILE_DELAY_UNTIL_REBOOT
Windows NT only: The function does not move the file until the operating system is restarted. The system moves the file immediately after AUTOCHK is executed, but before creating any paging files. Consequently, this parameter enables the function to delete paging files from previous startups.
How can I replace OrigionalFile under thses conditions?
====================================
how can temporary make the orginal file writable( remove read only flag) using filesystemobject
and then set it back to read only.
But if for security reasons (permissions) that is not possible then consider copying the file to another file
and then use the copy of the file (which is not read only)
MOVEFILE_DELAY_UNTIL_REBOO
Also try
Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
SetFileAttributes OriginalFile,&H2