Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Password input in batch file

Posted on 2005-04-19
12
Medium Priority
?
21,955 Views
Last Modified: 2012-06-27
Hello experts,

I need to write a batch file that will ask users for account and password and then will connect to different servers using these input data. I can do that with the following code:

REM ******** Begin ************
echo Enter username:
set /p USERID=

echo Enter password:
set /p PWD=

net use I: \\SERVER01\share %PWD% /USER:DOMAIN\%USERID% /PERSISTENT:no
net use J: \\SERVER02\share %PWD% /USER:DOMAIN\%USERID% /PERSISTENT:no
net use K: \\SERVER03\share %PWD% /USER:DOMAIN\%USERID% /PERSISTENT:no

REM ******** End ************

The password will be displayed in clear text on the screen while user input. I want to prevent that the password will be shown on the screen. Because of that I'm looking for a command line tool or any other method that will allow masqueraded user input and will store it in a variable. The batch must be executable on Windows 2000 and XP.

Does anyone have an idea how to do that?

Thanks in advance,
ghana
0
Comment
Question by:ghana
11 Comments
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 13813209
I'll be interested to see if someone comes up with a way; I've never seen one.
0
 
LVL 16

Expert Comment

by:JamesDS
ID: 13813225
ghana
Using standard batch commands it isn't possible to enter the password and have it displayed as other than clear text. You have a couple of choices:

Present the script as a web page or convert it to VBScript using an input box.
Replace the net use commands with this:

net use I: \\SERVER01\share * /USER:DOMAIN\%USERID% /PERSISTENT:no
net use J: \\SERVER02\share * /USER:DOMAIN\%USERID% /PERSISTENT:no
net use K: \\SERVER03\share * /USER:DOMAIN\%USERID% /PERSISTENT:no

The net use command itself will ask for the password, which is then not displayed. You will have to remove the bit at the start of the script that asks for a password. The downside of this is that each net use command will probably ask for a password - but if you're lucky it will cache the first one and you'll only get asked once. Only testing will tell you for sure.

Cheers

JamesDS
0
 
LVL 11

Author Comment

by:ghana
ID: 13813272
leew, I've never seen one too. That's why I'm asking now.   ;-)

JamesDS, thanks for your comment. One important feature of the script is that it should only aks 1 single time for the username and password. I did already some testing in the past. Because it won't cache the password and does prompt the user for every single connection I need a solution that will store the password in a variable to re-use it in multiple lines.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:JamesDS
ID: 13813308
ghana
In which case VBScript is your answer.

You may be able to specially format an input box, but the preferred method is presenting the whole script within a browser window and use the password input box features of HTML.

Cheers

JamesDS
0
 
LVL 11

Author Comment

by:ghana
ID: 13813549
JamesDS, I just want to repeat to find out whether I really understand your suggestion: The job can be done by a VBScript within a HTML page?

Okay, I'm familiar with HTML and the password input box. But I'm not familiar with VB. Do you have an example or do you now a site where I can find those examples. I don't want to learn VBScript at the moment and would be glad if could get a quick solution.
0
 
LVL 16

Expert Comment

by:JamesDS
ID: 13813701
ghana
Try www.15seconds.com

This is an excellent scripting resource and runs a number of mailing lists where the other members are generally very helpful.

This code will connect a drive mapping as a starter:

strConnectionString = "\\"& strFileServer & "\" & strShareName
Set objWSHNetwork = CreateObject("WScript.Network")
objWSHNetwork.MapNetworkDrive strDriveLetter & ":", strConnectionString, True

Cheers

JamesDS
0
 
LVL 11

Author Comment

by:ghana
ID: 13821830
After opening a question in the ASP section and discussing the problem there VBScript within a HTML page doesn't seem to be the solution. The problem is that VBScript code is then executed on the web server and not on the client. But the mapping must be done on the client...

Now I start searching again. What I need is something very similar to senvar.com (http://www.desktopian.org/addonsi_cmdln.shtml) but with an additional /pwd switch that will masquerade input on the screen with asteriks.
0
 
LVL 16

Expert Comment

by:JamesDS
ID: 13822127
ghana

I think this link will help you.

http://groups.msn.com/windowsscript/logonscripts.msnw

Cheers

JamesDS
0
 
LVL 11

Author Comment

by:ghana
ID: 13823290
Okay, I really found a solution that is working for me. I'm using the Kixtart scripting language to do that. For those who are interested I will post the code below.

Explanation: The user will be prompted to enter his username and password. To prevent that the password is visible on the screen while typing I'm setting both, foreground color and background color, to black (color n/n). Using the 'setl' command I can assign the content of the kix variables to the user defined variables (in this example 'cmduser' and 'cmdpwd'). In the last line a batch is started. In this batch you can now access the user input from the kix script using %cmduser% and %cmdpwd%. Because of security reasons it might be a good idea to add 'set cmdpwd=******' as last line in the batch file. Otherwise the password will stay in the memory in plain text.

If you have any questions, comments, please let me know.

; *************** BEGIN KIX SCRIPT ***************
dim $sUserID         ; account name
dim $sPwd            ; password for account in $sUserID

? "Please enter your user name: "
gets $sUserID
? "Please enter your password: "
color n/n
gets $sPwd
color w/n
setl "cmduser=$sUserID"
setl "cmdpwd=$sPwd"
shell "batchfile.cmd"
; *************** END KIX SCRIPT ***************


REM ************* BEGIN BATCHFILE.CMD *************
REM This is only an example. Displaying cmdpwd in plain text doesn't make sense in a real environment...   ;-)
echo You have entered the following data in the previous kix script:
echo User name=[%cmduser%]
echo Password=[%cmdpwd%]
pause
REM In the last line you should overwrite the plaint text password in the variable cmdpwd
set cmdpwd=*******
REM ************* END BATCHFILE.CMD *************
0
 
LVL 16

Expert Comment

by:JamesDS
ID: 13823662
ghana

Top solution, well done!
Cheers

JamesDS
0
 

Accepted Solution

by:
PAQ_Man earned 0 total points
ID: 13872205
Question Closed, 500 points refunded.
PAQ_Man
Community Support Moderator
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Use this step by step method when setting up QuickBooks Online. They will allow you to explore the various features of the advanced settings available to you.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

581 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