Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a batch file that prompts the user for a password, which I then store as a variable to be used later. Is there anyway to hide the text while it's being typed on the screen to keep other people from visually seeing what the user is entering.
I thought of changing the background color and text color to the same, but Windows XP won't let you.
Any ideas would be appreciated!

I don't know if you can do it directly using just cmd.exe's internal commands. For example, the SET /P command echoes the password back. Does anyone know of a way? In the meantime, here's a technique that uses a one-line VBScript program.
Paste the following line into a new file called GetPassword.vbs:
wscript.echo CreateObject("ScriptPW.Password").GetPassword()
Then use it from your batch file as follows:
for /f "tokens=*" %p in ('cscript /nologo GetPassword.vbs') do set password=%p
I hope that helps.
However, be careful. There are security risks when doing user input. For example, suppose you try to create a file full of passwords, by appending a user's password to it:
for /f "tokens=*" %p in ('cscript /nologo GetPassword.vbs') do set password=%p
echo %password% >> pwdfile.txtNow the user could enter something like
"xx && del \WINDOWS\system32\ImportantFile.exe" as his password (Where "ImportantFile.exe" is any file that you don't want to lose.) This can cause your 'echo' command above to trash your system.

You can use conset.exe with the /ph switch. When used, typed text will no be echoed back to STDOUT.
"Computer security." — Oxymoron

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |