Solved

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

Posted on 2013-01-27
8
596 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
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Create a specific short cut with a parameter. 2 180
robocopy 6 50
Xcopy / Robocopy Question 7 55
network copying issue 4 40
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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now