Solved

dos command to force file overwrite

Posted on 2008-10-02
5
10,832 Views
Last Modified: 2012-06-21
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?
0
Comment
Question by:the_bachelor
5 Comments
 
LVL 7

Assisted Solution

by:johnny_the_knife
johnny_the_knife earned 84 total points
ID: 22629342
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:

http://www.ss64.com/nt/runas.html
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 84 total points
ID: 22629354
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...
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 22629404
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.
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 84 total points
ID: 22724185
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.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

18 Experts available now in Live!

Get 1:1 Help Now