set batch file variables containing special characters
Posted on 2009-04-16
I'm working on a set of batch files that automate the "post-workstation imaging" tasks. Currently, I have a series of 3 batch files -- They are 99% functional -- the issue I'm running into is with users who have special characters in their passwords (like the & symbol). I'll use the following lines to prompt the user for their admin credentials:
set /p adun="Type your admin username: DA\"
%gctmp%\conset /ph adpw=Type your admin password:
I then use the %adun% and %adup% variables to query active directory using dsquery/dsget, and later to add machines to the domain using netdom and move them to the correct ou using dsmove. Of course when I do this, and the user has a special character in their password (like the & ), it cuts off everything from the "&" back.
I've found if I set a variable using quotes, it works fine, but the variable is being set from the user's input, and short of asking them to "surround your password with quotes if it contains special characters", is there another way to do this?
Of course, if the user's password doesn't contain any special characters, the scripts run fine, but our passwords must contain at least 2 special characters...
Also, a side-note: I'm using the conset program to set the adpw variable so the user's passowrd is not echoed back to them (or anyone else looking over their shoulder), but it appears to work the same way as the set command.