does windows 7 pro DOS COPY command overwrite open files?

my batch file has a command like    Copy File1 File2 /y

File 2 is an Access Data Base that is open.

I always thought copying to an open file would give Access Denied, but that does not seem to be the case.  

Both of my computers let the copy go forward with no warning which leads to data base corruption on the target file.

So, is this normal ???
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:

If you want it to copy only if it is not opened, one way is to check for the .LDB file that Access creates when the .MDB is open. If it doesn't exist, then do the copy. e.g. in a .bat file:
if not exist "\\server\share\whatever.ldb" copy "\\server\source\whatever.mdb" "\\server\share\whatever.mdb" /y

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JohnBusiness Consultant (Owner)Commented:
If you remove /Y, it will prompt. I do not use /Y and it always prompts for any copy.
rberkeConsultantAuthor Commented:
The batch file in question refreshes a client PC so its Front End.mdb database has the most recent copy from the server.  The old version ALWAYS exists.  

I need the batch file to say
if not OPEN "\\server\share\whatever.ldb" copy "\\server\source\whatever.mdb" "\\server\share\whatever.mdb" /y
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

rberkeConsultantAuthor Commented:
So your LDB idea would work, but what about a more general case where the file is open but does not have something like a ldb locking file?
JohnBusiness Consultant (Owner)Commented:
You asked why no warning and /Y is why no warning. If you  are happy with no warning, use /Y. You suggested you were not happy with no warning so do not use /Y.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
John, the OP asked about a warning in regard of an open file, not an existing file.

rberke, Access is different as it does not lock the file (completely) if in use - because Access is a client application using shared file network access. You could not do that with MSSQL at all (file is locked as a whole), but with a text file opened in Notepad (does not lock the file at all). So it really depends on the application if a and which kind of lock is applied.

COPY cannot know about the specific use of the file. Hence the "application" logic need to care about that, which means you have to check for a LDB file with Access.
rberkeConsultantAuthor Commented:
I was about to post my research when I saw Qlemo's post.  He and I are pretty much in agreement that database files are special cases that are not "Copy protected" at all (the /y  switch is completely ignored.)  It is not quite the same as a Notepad file. Notepad files are totally unlocked, and their name can be changed even while they are open.  But an open mdb file cannot have its name change.  

It is my belief that things were handled differently in XP, and that the MDBs were "copy protected" but I could be wrong – but I don’t have a windows XP machine to handy to test

I'll award points now.

Since I had already drafted my research, I am posting it below. It has a few minor additions that might be useful to future researchers.  

Further testing reveals that we were on the wrong track about the Copy program. The Windows Copy command protects most open files to prevent accidental destruction and the /Y parameter does NOT override that protection. (I tested it Excel, Word, project.Otm and all of those are protected.  I also tested it on .txt files that were opened with vba open update. None of these could be overwritten; they all got this error message:

  “The process cannot access the file because it is being used by another process.”

But Windows 7 Copy handles .mdb files totally differently. When working on an MDB the Copy function does not protect the target at all.  The /y switch is ignored.  The locking status is ignored.  Some other windows functions like Explorer Rename still provide protection.

Does anybody have any specific knowledge about that?  Ideally a pointer to MS documentation?
rberkeConsultantAuthor Commented:
It turns out that XP works the same as windows 7.

Copy file1.mdb to file2.mdb  will never say "Overwrite c:\aaatmp\file2.xls? (Yes/No/All):
and, it will never say  “The process cannot access the file because it is being used by another process.”

Somehow I never noticed this quirk about .mdb files in Windows XP and Windows 7.  It turns out that I have several "production" batch files that I thought were working, but now know to be unsafe.  Perhaps that explains why we have occasional mdb corruption.

I will fix the batch files by using NVIT's trick  "if not exist "\\server\share\whatever.ldb" copy "\\server\source\whatever.mdb" "\\server\share\whatever.mdb" /y.

 Of course, we now know that the /y flag is ignored for mdb files, so I will leave it off when I fix those batch files.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.