Link to home
Start Free TrialLog in
Avatar of Neal Hartman
Neal HartmanFlag for United States of America

asked on

MoveFileEx

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?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vinnyd79
vinnyd79

or maybe:

If GetAttr("C:\Myfile.txt") And vbReadOnly Then
    SetAttr "C:\Myfile.txt", vbNormal
End If
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)
Avatar of Neal Hartman

ASKER

It did not work with SystemFileObject but did work with the API. I should have tried that first.