How to give credentials in a batch script that cop

2019-01-22 01:38发布

The environment is Windows Web Server 2008, and I'm just trying to copy a folder full of files to a network location (a managed backup network folder). Here is my .bat file, running in the folder with my .bat files:

copy *.bak \\networklocation\*.bak
pause

however \\networklocation requires username x and password y, so running the script gives:

Logon failure: unknown user name or bad password.

I can't figure out a way to supply my credentials. I tried creating a scheduled task and modifying the security options, but this only seems to allow you to use credentials relevant to the machine (i.e. I try putting in username x and it can't find it).

How do I run this script with all the right permissions?

Solution:

net use \\networklocation\sharefolder password /USER:username
copy \*.bak \\networklocation\sharefolder\*.bak

2条回答
等我变得足够好
2楼-- · 2019-01-22 02:12

This is wrong.

The correct solution would be as follows:

net use X: "\\servername\share" /user:morgan password
查看更多
看我几分像从前
3楼-- · 2019-01-22 02:15

Try using the net use command in your script to map the share first, because you can provide it credentials. Then, your copy command should use those credentials.

net use \\<network-location>\<some-share>\ password /USER:username
查看更多
登录 后发表回答