如何在将文件复制到网络位置的批处理脚本中提供凭据? [英] How to give credentials in a batch script that copies files to a network location?

查看:24
本文介绍了如何在将文件复制到网络位置的批处理脚本中提供凭据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境是 Windows Web Server 2008,我只是想将一个装满文件的文件夹复制到网络位置(托管备份网络文件夹).这是我的 .bat 文件,在我的 .bat 文件所在的文件夹中运行:

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

但是\networklocation需要用户名x和密码y,所以运行脚本给出:

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

Logon failure: unknown user name or bad password.

我想不出一种方法来提供我的凭据.我尝试创建计划任务并修改安全选项,但这似乎只允许您使用与机器相关的凭据(即我尝试输入用户名 x 但它找不到).

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?

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

推荐答案

首先尝试在脚本中使用 net use 命令映射共享,因为您可以为其提供凭据.然后,您的复制命令应使用这些凭据.

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

不要在末尾留下

这篇关于如何在将文件复制到网络位置的批处理脚本中提供凭据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆