批次檔輸入密碼時不顯示

因為自製了一些批次檔,偶爾需要輸入密碼的時候,批次檔並不能處理密碼,所以輸入的時候會變成明文輸入。找了半天才有一個比較可以接受的方式,有需要的人可以參考看看。

@echo off

cls
echo 請在跳出視窗內輸入使用者名稱及密碼
If not exist %0 goto ERROR
type %0 | find "    " | find /v "Not Me!" > %TEMP%\UserIn.hta
start /w %TEMP%\UserIn.hta

call %TEMP%\UserIn.bat
echo Your user name is %USERNAME%
echo Your password is %PASSWORD%
:: Clean up
del %TEMP%\UserIn.hta
del %TEMP%\UserIn.bat
goto DONE

:ERROR
cls
echo %0 is not the full path and file name
echo for the batch file. You MUST call this
echo batch file with a full path and file name.
goto DONE

:HTA
:: All HTA code MUST be indented four or more spaces.
    <html>
    <head>
    <title>Password Entry</title>
    <hta:application>
    <script language="vbscript">
        window.resizeTo 250,200
        Sub SaveBatch()
            Set fs = CreateObject("Scripting.FileSystemObject")
            strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.bat"))
            Set ts = fs.OpenTextFile(strFile, 2, True)
            ts.WriteLine "SET USERNAME=" &amp; document.Forms(0).elements("username").value
            ts.WriteLine "SET PASSWORD=" &amp; document.Forms(0).elements("password").value
            ts.Close
        End Sub
    </script>
    </head>
    <body>
    <form>
        <br>使用者名稱:
        <br><input type=text name=username tabindex=1>
        <br>密碼:
        <br><input type=password name=password tabindex=2>
        <br><input type=button language="vbscript" value="OK" onclick="SaveBatch : Window.Close">
    </form>
    <script language=vbscript>
        document.Forms(0).elements("username").focus
    </script>
    </body>
    </html>

:DONE

來源:
Enter username , password in form using batch file / Hide password batch file
http://j4info.blogspot.com/2013/07/enter-username-password-in-form-using.html