gmeroni
gmeroni

Reputation: 571

Store Username and Password with a pre-configured Connection

I managed to create an executable to run Store Username and Password with this code:

rundll32.exe keymgr.dll, KRShowKeyMgr
exit

I'm asking if it's possible to prompt the windows to configure the new connection with the address already configured. As you can see in the image below, I would like to let the user that open this file just fill out his user and password.

WindowsCredential

Upvotes: 0

Views: 125

Answers (1)

Squashman
Squashman

Reputation: 14290

Why don't you just use CMDKEY.exe http://ss64.com/nt/cmdkey.html

EDIT:

@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

Second EDIT: Code with Hidden Password Input

@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

Upvotes: 1

Related Questions