批处理文件命令隐藏密码 [英] Batch File Command Hide Password

查看:435
本文介绍了批处理文件命令隐藏密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个批处理文件,我写信给打开腻子,并希望使之成为别人的通用脚本。该脚本如下:

I have this batch file I wrote to open putty and want to make it a universal script for others. The script is as follows

@echo off
::Written by Mark Gulick::
::Today's Date 20150316::

set /p U="Enter Username: "
set /p P="Enter Password: "
set /p DC="Enter DC Number: "
start /d "C:\Program Files (x86)\putty\" PUTTY.EXE %U%@b0%DC%db -pw %P%
pause

我想使密码不显示出来,并试图在这里的一些地区,还没有找到一个,将工作。我可能是做错了。我对我的脚本有点生疏。我缺少的东西,或者我应该用别的其他则set命令?

I would like to make the password not show up and have tried some areas on here and haven't found one that will work. I might be doing it wrong too. I'm a little rusty on my scripting. Am I missing something or should I use something else other then the set command?

推荐答案

您可以做这样的事情:

@echo off & setlocal DisableDelayedExpansion
Title %~n0
Mode 50,5 & Color 0E
set /p U="Enter Username : "
Call:InputPassword "Enter Password" P
set /p DC="Enter DC Number: "
setlocal EnableDelayedExpansion
start /d "C:\Program Files (x86)\putty\" PUTTY.EXE !U!@b0!DC!db -pw !P!
pause
::***********************************
:InputPassword
Cls
echo.
echo.
set "psCommand=powershell -Command "$pword = read-host '%1' -AsSecureString ; ^
    $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
      [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
        for /f "usebackq delims=" %%p in (`%psCommand%`) do set %2=%%p
)
goto :eof     
::***********************************

这篇关于批处理文件命令隐藏密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆