Solved

dos command to force file overwrite

Posted on 2008-10-02
5
10,993 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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