Last active
April 26, 2021 13:14
-
-
Save lunarplasma/2a2f4fa464198e210fcb51fef44fbd3d to your computer and use it in GitHub Desktop.
Batch File password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :: This batch file demonstrates how to use a powershell command to do password entry. The password entry part | |
| :: is done as a batch file function. | |
| :: As ever, call it with | |
| :: CALL :Func param1, param2 | |
| @ECHO OFF | |
| CALL :GET_PASSWORD "Enter password", PASSWORD | |
| ECHO Password was: %PASSWORD% | |
| EXIT /b 0 | |
| :: Usage: CALL :GET_PASSWORD prompt output | |
| :: prompt: Text prompt to the user | |
| :: output: Variable to set the password | |
| :GET_PASSWORD | |
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source for the powershell stuff: https://stackoverflow.com/a/20343074/3274353