Solved

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

Posted on 2013-01-27
8
605 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

23 Experts available now in Live!

Get 1:1 Help Now