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!
Visual Basic Classic

Avatar of undefined
Last Comment
Neal Hartman
ASKER CERTIFIED SOLUTION
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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
Neal Hartman
Flag of United States of America image

ASKER

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

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo