Solved

Get User Input in a bat file

Posted on 2008-06-19
8
1,865 Views
Last Modified: 2008-06-25
Hi All,

I'm trying to write a bat file with the use of the "Net Use" command like this:
net use k: \\mypcname\c$ password /User:Operator1

I don't want to hard code the password in the bat file. How can I ask the user to input this password while running this bat file. Please advise. Thanks.
0
Comment
Question by:cplau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 21828062
set /p pw=Enter your password:
0
 
LVL 7

Accepted Solution

by:
fhmc earned 125 total points
ID: 21828135
how about

mapk.bat
::capture user input and store it in an environment variable
set /p netusepw=Please Enter Your Password:
::execute net user command and pass environment variable
net use k: \\mypcname\c$ %netusepw% /user:Operator1
::clear previously stored data in environment variable
set netusepw=asdfasdf
:end
0
 
LVL 7

Expert Comment

by:fhmc
ID: 21828142
argh...  sirbounty beat me to it.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 67

Expert Comment

by:sirbounty
ID: 21828153
just use
setlocal
at the head of your batch file - that way you won't have to clear the password, regardless of the variable you use for it...
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 21828672
Can't try it right now but... if you just leave the password off the net use line does it not prompt the user for the password anyway if it doesn't match their current one?

Steve
0
 
LVL 85

Expert Comment

by:oBdA
ID: 21829206
The correct way is actually to use an asterisk instead of leaving out the password in the "net use".
That way,
- the password will not be displayed when it's entered
- Windows won't try first to authenticate with the current user's password, causing possible lockouts and auditing events.

net use k: \\mypcname\c$ * /User:Operator1
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 21829376
Thanks oBdA, thats what I was thinking of... haven't done it in ages as of course 99.9% of the time there is domain authentication involved or the users have the same user/passwords on the different systems.

Either way it's a better solution IMO than having a prompt where the user has to type their password into a visible prompt and store it in an environment variable, might aswell just put the password in the batch file if so!

Steve
0
 
LVL 7

Expert Comment

by:fhmc
ID: 21832893
I agree, dragon-it's approach is far superior to the env. variable approach (I didn't realize "net use" could natively prompt for credentials.)  noted.

that said, I don't agree the security concerns associated to defining and almost immediately clearing a password in an environmnet variable is anything close to the concerns associated w/ storing a password in clear text in a .bat file...
0

Featured Post

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.

Question has a verified solution.

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

It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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