Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12989
  • Last Modified:

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?
0
the_bachelor
Asked:
the_bachelor
3 Solutions
 
johnny_the_knifeCommented:
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
 
sirbountyCommented:
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
 
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.
0
 
t0t0Commented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now