Solved

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

Posted on 2013-01-27
8
630 Views
Last Modified: 2013-01-28
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
Comment
Question by:gbm33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:EMJSR
ID: 38824975
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
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 38825066
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
 

Author Comment

by:gbm33
ID: 38825104
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 9

Expert Comment

by:EMJSR
ID: 38825105
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
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 38825143
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38825753
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38825755
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
 

Author Comment

by:gbm33
ID: 38827619
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question