Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
967 views
in Technique[技术] by (71.8m points)

permissions - How to give credentials in a batch script that copies files to a network location?

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 \networklocationsharefolder password /USER:username
copy *.bak \networklocationsharefolder*.bak
question from:https://stackoverflow.com/questions/3854026/how-to-give-credentials-in-a-batch-script-that-copies-files-to-a-network-locatio

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Don't leave a trailing at the end of the


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...