Reading Passwords Into a .cmd script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Dosage
Posts: 1
Joined: 02 Oct 2018 03:27

Reading Passwords Into a .cmd script

#1 Post by Dosage » 02 Oct 2018 03:40

Hi,

I have a drive-mapping script, mapping.cmd, that uses different accounts to map different drives.
Some of the account passwords have special characters in them like % which would be parsed incorrectly if entered straight into the mapping.cmd file.
So I've put the password containing the % character into a separate file, pwd.txt, and this imports in fine when called like this:

Code: Select all

net use p: \\[some path] /user:[some domain]\[some ID] < pwd.txt
So far so good. This works and maps the drive using the password with the % in it, from pwd.txt

Just wondering, if I wanted to map another drive in mapping.cmd, which again uses a special character, if I can in some way list multiple passwords in the same pwd.txt file, rather than the clunkier method of using yet another file, say pwd2.txt, just to hold this other password e.g.

Code: Select all

net use p: \\[some path] /user:[some domain]\[some ID] < pwd.txt
net use q: \\[some path] /user:[some domain]\[some ID] < pwd2.txt
If this is possible - How would I infer the delimit between different passwords in the pwd.txt file and/or refer to them separately in the < pwd.txt part?

Or should I just use the clunky method?

carlos
Expert
Posts: 487
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Reading Passwords Into a .cmd script

#2 Post by carlos » 04 Oct 2018 19:58

Can you try this, is only a idea that myabe can work:

Put on a single file the password in order of mapping:

pass.txt

Code: Select all

abcd
efgh
and process.cmd

Code: Select all

(
net use p: \\[some path] /user:[some domain]\[some ID]
net use q: \\[some path] /user:[some domain]\[some ID]
) < pass.txt

Post Reply