Solved

MoveFileEx

Posted on 2004-03-30
5
553 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:Neal Hartman
5 Comments
 
LVL 13

Accepted Solution

by:
crazyman earned 500 total points
ID: 10713969
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

SetFileAttributes OriginalFile,&H2
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10714118
or maybe:

If GetAttr("C:\Myfile.txt") And vbReadOnly Then
    SetAttr "C:\Myfile.txt", vbNormal
End If
0
 
LVL 6

Expert Comment

by:___XXX_X_XXX___
ID: 10714177
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.
0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 10714483
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)
0
 
LVL 1

Author Comment

by:Neal Hartman
ID: 10716537
It did not work with SystemFileObject but did work with the API. I should have tried that first.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now