dos command to force file overwrite

her is my problem, I trying to write a batch file that will overwrite a a file by another.
the syntax that i got is
copy file1 file2 /y

simple enough eh? Only I'm getting Access denied.
How do I force the copy?
Or How do I put credentials in the batch file so the command works?
Or Is the away to use batch files to impersonate a user?
Who is Participating?
t0t0Connect With a Mentor Commented:
Simple.... Sounds like you're trying to copy over a read-only file.

Use DOS's XCOPY instead of COPY, ie:

    XCOPY source destination /R /C /Y

Easy Peasey !! But most importantly, use the /R switch allows you to overwrite read-only files.
johnny_the_knifeConnect With a Mentor Commented:
If you are running on Windows, you can use RunAs to execute commands in the context of another account.  This article provides the information you will need:
sirbountyConnect With a Mentor Commented:
If the file is in use, you may not be able to - not without closing/terminating the access to the file....

You might try using robocopy.  Add the /b switch to put the copy in 'backup' mode...
Lee W, MVPTechnology and Business Process AdvisorCommented:
runas will not permit you to store authentication information.  If you are not an administrator then you may not be able to overwrite the file.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.