使用预配置的连接存储用户名和密码

时间:2015-10-22 15:35:28

标签: windows batch-file

我设法使用以下代码创建一个可执行文件来运行Store Username and Password

rundll32.exe keymgr.dll, KRShowKeyMgr
exit

我在询问是否可以提示窗口使用已配置的地址配置新连接。如下图所示,我想让打开此文件的用户填写他的用户名和密码。

WindowsCredential

1 个答案:

答案 0 :(得分:1)

为什么不使用CMDKEY.exe http://ss64.com/nt/cmdkey.html

编辑:

@echo off

:username
cls
SET "username="
SET /P "username=Enter your username:"
IF NOT DEFINED username GOTO username

:password
cls
SET "password="
SET /P "password=Enter your password:"
IF NOT DEFINED password GOTO password

cmdkey /add:Server /user:%username% /pass:%password%

pause

第二次编辑:带有隐藏密码输入的代码

@echo off &setlocal

:username
cls
SET "username="
SET /P "username=Enter your username:"
IF NOT DEFINED username GOTO username

:password
cls
<nul set /p "=Enter your password: "
call :HInput password
IF NOT DEFINED password GOTO password

setlocal EnableDelayedExpansion
cmdkey /add:Server /user:%username% /pass:!password!
pause
goto :eof


:HInput [ByRef_VarName]
:: inspired by Carlos
:: improved by pieh-ejdsch
if "%__HI__%" neq "__HI__" (
  setlocal DisableDelayedExpansion
  set "S=" &set "N=0" &set "__HI__=__HI__"
  for /f %%i in ('"prompt;$h&for %%i in (1) do rem"') do set "BS=%%i"
)
set "C="
for /f "eol=1 delims=" %%i in ('xcopy /lwq "%~f0" :\') do set "C=%%i"
set "C=%C:~-1%"
setlocal EnableDelayedExpansion
if not defined C (
  echo(
  if "%~1"=="" (
    echo(!S!
    endlocal &endlocal &exit /b %N%
  ) else (
    if defined S (
      for /f delims^=^ eol^= %%i in ("!S!") do endlocal &endlocal &set "%~1=%%i" &exit /b %N%
    ) else endlocal &endlocal &set "%~1=" &exit /b 0
  )
)
if "!BS!"=="!C!" (
  set "C="
  if defined S set /a "N -= 1" &set "S=!S:~,-1!" &<nul set /p "=%BS% %BS%"
) else set /a "N += 1" &<nul set /p "=*"
if not defined S (
  endlocal &set "N=%N%" &set "S=%C%"
) else for /f delims^=^ eol^= %%i in ("!S!") do endlocal &set "N=%N%" &set "S=%%i%C%"
goto HInput