21

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!

Sandy
  • 11,332
  • 27
  • 76
  • 122

3 Answers3

22

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

Mofi
  • 46,139
  • 17
  • 80
  • 143
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
  • 1
    I don't think they really need to *map* it, though. It should be enough simply to *connect* to the shared resource. So, replacing `Z:` with `*` should work as well, if I'm not missing anything. – Andriy M Jan 29 '13 at 08:54
  • net use * will map a drive too ... – Loïc MICHEL Jan 29 '13 at 09:05
  • I removed that `Z:` path at all. And credentials are getting added and worked. But not persistent. It asks again after I logoff and login. – Sandy Jan 29 '13 at 09:10
  • why not use a drive letter ? did you use /persistent:yes – Loïc MICHEL Jan 29 '13 at 09:12
  • yes....I used. Moreover can I delete credentials with this? +1 by the way – Sandy Jan 29 '13 at 09:17
  • You are right, `*` assigns an available letter automatically. I meant removing the drive assignment, just forgot how it was done. – Andriy M Jan 29 '13 at 09:28
  • @rapsalands what do you mean "delete credentials" ?? – Loïc MICHEL Jan 29 '13 at 10:03
  • if I ran the above command....then I will able to access path without using username and password. I will finish my required changes. Then I want to delete credentials so that if I try accessing the path again, it should ask for username and password. If it does not make any sense, let me know. However, I don't understand these server and remote stuff much – Sandy Jan 29 '13 at 10:44
  • @rapsalands you just have to disconnect the drive : `net use Z: /D` – Loïc MICHEL Jan 29 '13 at 10:47
16

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
5

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 :)