Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-27
8
Medium Priority
?
650 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 96

Accepted Solution

by:
Lee W, MVP earned 2000 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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 96

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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