JSI Tip 8610. How can I prevent a script from echoing a user's response?

I have scripted TypeHidden.bat to hide a user's response to a sensitive prompt, like a password.

The syntax for using TypeHidden.bat is:

TypeHidden "Your Message" Response


"Your Message" is the message you want typed to the user.
Response       is a call directed environment variable that will contain the hidden response.
Because the user cannot see their response, they are asked to Please re-type to confirm your entry.

NOTE: This works on Windows XP and later.

TypeHidden.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: TypeHidden "Your Message" Respnse&goto :EOF
set msg=%1
set vb="%temp%\pw_%RANDOM%.vbs"
set msg=¥%msg%¥
set msg=%msg:¥"=%
set msg=%msg:"¥=%
set msg=%msg:¥=%
echo WScript.Echo CreateObject("ScriptPW.Password").GetPassword>%vb%
@echo %msg%
for /f "tokens=*" %%a in ('cscript.exe //Nologo %vb%') do (
 set response=%%a
set response=%response:"=¥%
@echo Please re-type to confirm your entry.
for /f "tokens=*" %%a in ('cscript.exe //Nologo %vb%') do (
 set confirm=%%a
set confirm=%confirm:"=¥%
if "%response%" NEQ "%confirm%" goto nq
set response=%response:¥="%
del /q %vb%
endlocal&set %2=%response%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.