Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 653
  • Last Modified:

Using a DOS command how to access a server with an "&" in the password

I am using the following command to log onto a Windows 2008 server.

net use \\server abc&def /user: administrator

The error message that is returned is 'd' is not recognized as an internal or external command, operable program, or batch file.

Obviously, the "&" is causing a problem.  How can I access the server with an "&" in the password. I would like to not have to change the password. I have tried putting the password in single and double quotes but to no good effect.
0
gbm33
Asked:
gbm33
  • 2
  • 2
  • 2
  • +1
1 Solution
 
EMJSRCommented:
If you typed the command exactly that way, try putting the password back in quotation marks and do not add a space after /user:. So:

net use \\server "abc&def" /user:administrator
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
The & character on the command line is intended to concatenate two commands.  For example:

NET STOP SPOOLER & NET START SPOOLER

has the effect of stopping the print spooler and then immediately starting it (restarting).

I've never used ampersands in passwords so I'm not sure how to deal with having them specified on the command line - or if you can.  The only thing I can suggest is to use the ^escape character.

net use \\server abc^&def /user:administrator

That said, it's HORRIBLY UNWISE to code in an administrator password to a patch file in clear text.  If you want to map a drive from the command line, then just omit the password and you'll be prompted for it.
0
 
gbm33Author Commented:
leew: The ^ did the trick.  Thank you. I nevertheless will go about changing the password. I will agree that it is absolutely not a good thing to put a password in a batch file. The reason for the password is that during an automated backup process an external server is being accessed.  I'll post another question to see is someone has an idea on how access can be made without being prompted for a password.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
EMJSRCommented:
If it's access to a network resource, I would simply map a network drive and provide folder permissions to the users that need access. If it's administrator then you can login as such and you should have permissions anyway. But on a Windows domain I would simply create a new user account with Domain Admin and if necessary Enterprise Admin rights and that would do it.

Then you can run a login script mapping a network drive such as: net use <driverletter>: \\server\<folder> and you don't need to specifiy the password/username.
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
I would instead recommend that you create a user account for the task at hand so that changing the administrator password doesn't potentially mess up other services / scripts where it may be used (ill-advisedness not withstanding).
0
 
Steve KnightIT ConsultancyCommented:
i too would suggest doing away with the & in the password if you can, and if you need to specify on commandline then avoid %!&"><| at least.
 http://scripts.dragon-it.co.uk/links/batch-password1
you can use various techniques such as the one on my page below to hide the password from a casual observer, and if this is stored on one server connecting to this presumably non domain external server
0
 
Steve KnightIT ConsultancyCommented:
hmm caught submit on mobile sorry....
was just saying while it isnt best pratice, if needed for connecting to non domain resource then just make sure batch file is suitably secure and hide password as above if you want.
0
 
gbm33Author Commented:
leew: Thank you for your suggestion.  Accordingly, I followed your instructions and my script runs just fine without a password.

dragon-it: Your website is quite comprehensive with its myriad script suggestions. I have already bookmarked the site. Thank you very much.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now