Solved

MoveFileEx

Posted on 2004-03-30
5
563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
passing a value with stream reader AFTER a ";" 3 92
MS Date Picker 64 bit 32 bit issue 12 72
Sub or Function is not defined 6 59
VBA: loop recent folder and copy txt file. 8 56
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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