xcopy with credentials on remote machine [closed]

那年仲夏 提交于 2019-12-18 11:52:44

问题


I am trying to access a remote server on a different domain through its IP address. In run command I entered the following

\\XXX.XXX.XXX.XXX\C$\Program Files\

I get a pop up window asking for username and password. I enter it, and accessed the path. When I try accessing the folder again it do not ask for my password. But when I restart, it does give the popup again.

Is there a way to add my credentials?? Lets say my domain\username is MyDomain\RapsyTree. I tried the following:

cmdkey /generic:TERMSRV/YYY.YY.YYY.YYY /user:YourDomain\rapsalands /pass:secretPass

The credentials are getting added. But I am still getting the pop up for username and password.

Actually I am trying to xcopy some files on this server on different domain. But I need to do it with different credentials. I am using batch files. Any pointers will be of great help. Let me know if I am not clear. I am using Windows 7 Thanks!


回答1:


You just have to map a network drive:

net use Z: \\XXX.XXX.XXX.XXX\C$ password /user:domain\username 

If you want the drive to reconnect at next logon, add the option /persistent:yes




回答2:


You can also try this. pass the username and password as arguments. After copy it deletes the mapping & disconnects.

SET username=%1
SET password=%2
net use "\\xxx.xxx.xxx.xxx\Some Folder" %password% /user:domain\%username%
:copy
copy "\\xxx.xxx.xxx.xxx\Some Folder\New.txt" "D:\new.txt"
IF ERRORLEVEL 0 goto disconnect
goto end
:disconnect 
net use "\\xxx.xxx.xxx.xxx\Some Folder" /delete
goto end
:end



回答3:


try putting the IP in double quotes. It worked for me.

net use "\\xxx.xxx.xxx.xxx\Some Folder" password /user:domain\username

Keep me posted :)



来源:https://stackoverflow.com/questions/14578175/xcopy-with-credentials-on-remote-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!