2

I'm trying to send network credentials using Net Use command.

This is what I have:

@echo off
net use \\<serverName>\<shareFolder>\ passw0rd /USER:domain.com\UserName
PAUSE

This automatically inserts the username and Domain but for some reason not the password!!

I have tried it like this as well:

@echo off
net use \\<serverName>\<shareFolder>\ /USER:domain.com\UserName passw0rd 
PAUSE

I have checked the paths I'm using and they definitely work. When i copy them out and paste in RUN they work.

Same goes for the username and passwords.

Everything in google search is purple cause I've clicked on all the links :/


Ok, I thought I had it...

I tried it like this:

@echo off
net use \\<serverName>\<shareFolder>\ <mapName> /USER:domain.com\UserName passw0rd 
PAUSE

And it worked, but only because i entered the password before i tried it like this and then it remembered the password.

So I'm still looking for a way.

Please help.

Werner van den Heever
  • 745
  • 6
  • 17
  • 40

3 Answers3

4

Does the password contain special characters like % / ~ or similar characters with special meaning in batch files?

Yes, then enclose the password in double quotes.

Use also double quotes around UNC path and test if that makes a difference.

What I miss in all your net use commands is the device name usually specified left of UNC path to shared folder to map the shared folder to a drive letter. Therefore it could be that the password is interpreted as device name.

But according to your question you want to pass only the user credentials and password to be able to access the shared folder using UNC path. However, I suggest to test if it makes a difference really mapping the shared folder to a drive letter. I don't know if the password string is interpreted as device name if no device name specified and can't test it by myself at the moment.

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • Thank you @Mofi. Would really appreciate if Microsoft updated its documentation on this. – EngineeringSQL May 25 '17 at 12:49
  • @EngineeringSQL You mean [net use](https://technet.microsoft.com/en-us/library/gg651155.aspx) documentation which contains a remark about using quotation marks, but only with regard to server name? Well, documentation of [cmd](https://technet.microsoft.com/en-us/library/cc771320.aspx) contains the information when an argument can be specified __without__ quotation marks (on using `/c` or `/k`). In general it is always more safe to use quotation marks on arguments independent on being really needed or not. – Mofi May 25 '17 at 13:48
0
@echo off
net use <MapDriveName> \\<serverName>\<ShareFolder>\ /PASSWORD:<Passw0rd> /USER:<UserName>
PAUSE

This one works for me. Finally :) Hope this can help someone else as well.

Werner van den Heever
  • 745
  • 6
  • 17
  • 40
-1

net use Y: \server_name OR ipaddress\shared /user:domainname\%username%

Starry
  • 1