Hide Password typed in Console - Batch scriptBatch File Command Hide PasswordHide keyboard input for password in console via batch fileHow can I pass arguments to a batch file?Split long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?How to prevent auto-closing of console after the execution of batch fileHow to sleep for five seconds in a batch file/cmdPowerShell says “execution of scripts is disabled on this system.”How to “comment-out” (add comment) in a batch/cmd?java.lang.NoClassDefFoundError when calling the Java function from Powershell ScriptBatch: Set password with special characters to variablePassword set in batch file not taking last character
What is "aligned sequences" and "consensus sequence" in the context of sequence logo? How to compute these?
Why is it "on the inside" and not "in the inside"?
List of visa access for each country
Nested keyval proper parsing
How do I learn to recognise what is worth publishing
How to find the mass density function of a solid given its total mass, its volume and the position of its center of mass?
Why would anyone ever invest in a cash-only etf?
Are there any unpublished Iain M. Banks short stories?
Dual nationality and return to US the day the US Passport expires
Anti-cheating: should there be a limit to a number of toilet breaks per game per player?
What's the importance of the plane hijacking to the plot of Suspiria (2018)?
Examples of simultaneous independent breakthroughs
How many oliphaunts died in all of the Lord of the Rings battles?
Is it okay for me to decline a project on ethical grounds?
Summoning A Technology Based Demon
Exploiting the delay when a festival ticket is scanned
Does dual boot harms laptop battery or reduces it's life?
Why radial coordinate of a particle must decrease continuously once it is inside the Schwarzschild radius?
Why is the Apollo LEM ladder so far from the ground?
Are fretless stringed instruments used mainly for melody?
Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?
Does Wolfram Mathworld make a mistake describing a discrete probability distribution with a probability density function?
How to access HTML input values from Twig and vice versa
How did the Axis intend to hold the Caucasus?
Hide Password typed in Console - Batch script
Batch File Command Hide PasswordHide keyboard input for password in console via batch fileHow can I pass arguments to a batch file?Split long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?How to prevent auto-closing of console after the execution of batch fileHow to sleep for five seconds in a batch file/cmdPowerShell says “execution of scripts is disabled on this system.”How to “comment-out” (add comment) in a batch/cmd?java.lang.NoClassDefFoundError when calling the Java function from Powershell ScriptBatch: Set password with special characters to variablePassword set in batch file not taking last character
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Powershell command used in BAT file is eliminating the escape character available in the password specified by user in the console and saving it in a file.
I have a BAT script which prompt the user to specify the password in console. Password should be masked as ***** while user typing it in console. Password will be something like wel!123. This password is saved into variable and finally getting copied to a text file. I got few suggestion use the below code in my BAT file, but the escape character in the actual password( Wel!123) is getting eliminated and saving the password as Wel123 into login.txt file.
SetLocal
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -
AsSecureString; $BSTR=
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd);
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
@echo %pwd%>>login.txt
powershell batch-file
|
show 1 more comment
Powershell command used in BAT file is eliminating the escape character available in the password specified by user in the console and saving it in a file.
I have a BAT script which prompt the user to specify the password in console. Password should be masked as ***** while user typing it in console. Password will be something like wel!123. This password is saved into variable and finally getting copied to a text file. I got few suggestion use the below code in my BAT file, but the escape character in the actual password( Wel!123) is getting eliminated and saving the password as Wel123 into login.txt file.
SetLocal
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -
AsSecureString; $BSTR=
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd);
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
@echo %pwd%>>login.txt
powershell batch-file
2
I recommend doing this entirely in Powershell.
– UnhandledExcepSean
Mar 26 at 19:51
Can you tell me how to do it
– user78873
Mar 26 at 19:57
Possible duplicate of Batch File Command Hide Password
– Squashman
Mar 26 at 20:11
You are missing some stuff in your code. The reason the^does not get written tologin.txtis because the variable is expanded before execution and assumes you want to use the^as an escape character. You either need to escape the escape with string substitution or output the variable with delayed expansion.
– Squashman
Mar 26 at 20:15
1
@mklement0, you are probably correct. I kept focusing on what the user was writing because they kept saying ESCAPE. The exclamation is not an escape.
– Squashman
Mar 26 at 20:37
|
show 1 more comment
Powershell command used in BAT file is eliminating the escape character available in the password specified by user in the console and saving it in a file.
I have a BAT script which prompt the user to specify the password in console. Password should be masked as ***** while user typing it in console. Password will be something like wel!123. This password is saved into variable and finally getting copied to a text file. I got few suggestion use the below code in my BAT file, but the escape character in the actual password( Wel!123) is getting eliminated and saving the password as Wel123 into login.txt file.
SetLocal
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -
AsSecureString; $BSTR=
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd);
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
@echo %pwd%>>login.txt
powershell batch-file
Powershell command used in BAT file is eliminating the escape character available in the password specified by user in the console and saving it in a file.
I have a BAT script which prompt the user to specify the password in console. Password should be masked as ***** while user typing it in console. Password will be something like wel!123. This password is saved into variable and finally getting copied to a text file. I got few suggestion use the below code in my BAT file, but the escape character in the actual password( Wel!123) is getting eliminated and saving the password as Wel123 into login.txt file.
SetLocal
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -
AsSecureString; $BSTR=
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd);
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
@echo %pwd%>>login.txt
powershell batch-file
powershell batch-file
asked Mar 26 at 19:35
user78873user78873
187 bronze badges
187 bronze badges
2
I recommend doing this entirely in Powershell.
– UnhandledExcepSean
Mar 26 at 19:51
Can you tell me how to do it
– user78873
Mar 26 at 19:57
Possible duplicate of Batch File Command Hide Password
– Squashman
Mar 26 at 20:11
You are missing some stuff in your code. The reason the^does not get written tologin.txtis because the variable is expanded before execution and assumes you want to use the^as an escape character. You either need to escape the escape with string substitution or output the variable with delayed expansion.
– Squashman
Mar 26 at 20:15
1
@mklement0, you are probably correct. I kept focusing on what the user was writing because they kept saying ESCAPE. The exclamation is not an escape.
– Squashman
Mar 26 at 20:37
|
show 1 more comment
2
I recommend doing this entirely in Powershell.
– UnhandledExcepSean
Mar 26 at 19:51
Can you tell me how to do it
– user78873
Mar 26 at 19:57
Possible duplicate of Batch File Command Hide Password
– Squashman
Mar 26 at 20:11
You are missing some stuff in your code. The reason the^does not get written tologin.txtis because the variable is expanded before execution and assumes you want to use the^as an escape character. You either need to escape the escape with string substitution or output the variable with delayed expansion.
– Squashman
Mar 26 at 20:15
1
@mklement0, you are probably correct. I kept focusing on what the user was writing because they kept saying ESCAPE. The exclamation is not an escape.
– Squashman
Mar 26 at 20:37
2
2
I recommend doing this entirely in Powershell.
– UnhandledExcepSean
Mar 26 at 19:51
I recommend doing this entirely in Powershell.
– UnhandledExcepSean
Mar 26 at 19:51
Can you tell me how to do it
– user78873
Mar 26 at 19:57
Can you tell me how to do it
– user78873
Mar 26 at 19:57
Possible duplicate of Batch File Command Hide Password
– Squashman
Mar 26 at 20:11
Possible duplicate of Batch File Command Hide Password
– Squashman
Mar 26 at 20:11
You are missing some stuff in your code. The reason the
^ does not get written to login.txt is because the variable is expanded before execution and assumes you want to use the ^ as an escape character. You either need to escape the escape with string substitution or output the variable with delayed expansion.– Squashman
Mar 26 at 20:15
You are missing some stuff in your code. The reason the
^ does not get written to login.txt is because the variable is expanded before execution and assumes you want to use the ^ as an escape character. You either need to escape the escape with string substitution or output the variable with delayed expansion.– Squashman
Mar 26 at 20:15
1
1
@mklement0, you are probably correct. I kept focusing on what the user was writing because they kept saying ESCAPE. The exclamation is not an escape.
– Squashman
Mar 26 at 20:37
@mklement0, you are probably correct. I kept focusing on what the user was writing because they kept saying ESCAPE. The exclamation is not an escape.
– Squashman
Mar 26 at 20:37
|
show 1 more comment
2 Answers
2
active
oldest
votes
! characters disappearing is unrelated to PowerShell - it suggests that cmd.exe's enabledelayedexpansion option is in effect, in which case ! serves as a variable-name delimiter - and in which case isolated ! chars. are simply discarded.
As an aside: ! is therefore not an escape character.
You therefore need to:
Disable delayed variable expansion with
setLocal disabledelayedexpansion:- Note that delayed expansion is off by default, so something in your environment must have turned it on.
Additionally, as Squashman points out,
^characters -cmd.exe's escape char. in unquoted strings - would be "eaten", so you must escape all^chars. as^^, which can you do with%pwd:^=^^%.
To put it all together:
@echo off
setLocal disabledelayedexpansion
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -AsSecureString; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd); [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
echo %pwd:^=^^%>>login.txt
Glad to hear it, @user78873.
– mklement0
Apr 10 at 13:38
add a comment |
To convert this to PowerShell, you have most of the code already written:
$pwd = Read-Host 'Enter Your Password' -AsSecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) | Add-Content -Path login.txt
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365022%2fhide-password-typed-in-console-batch-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
! characters disappearing is unrelated to PowerShell - it suggests that cmd.exe's enabledelayedexpansion option is in effect, in which case ! serves as a variable-name delimiter - and in which case isolated ! chars. are simply discarded.
As an aside: ! is therefore not an escape character.
You therefore need to:
Disable delayed variable expansion with
setLocal disabledelayedexpansion:- Note that delayed expansion is off by default, so something in your environment must have turned it on.
Additionally, as Squashman points out,
^characters -cmd.exe's escape char. in unquoted strings - would be "eaten", so you must escape all^chars. as^^, which can you do with%pwd:^=^^%.
To put it all together:
@echo off
setLocal disabledelayedexpansion
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -AsSecureString; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd); [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
echo %pwd:^=^^%>>login.txt
Glad to hear it, @user78873.
– mklement0
Apr 10 at 13:38
add a comment |
! characters disappearing is unrelated to PowerShell - it suggests that cmd.exe's enabledelayedexpansion option is in effect, in which case ! serves as a variable-name delimiter - and in which case isolated ! chars. are simply discarded.
As an aside: ! is therefore not an escape character.
You therefore need to:
Disable delayed variable expansion with
setLocal disabledelayedexpansion:- Note that delayed expansion is off by default, so something in your environment must have turned it on.
Additionally, as Squashman points out,
^characters -cmd.exe's escape char. in unquoted strings - would be "eaten", so you must escape all^chars. as^^, which can you do with%pwd:^=^^%.
To put it all together:
@echo off
setLocal disabledelayedexpansion
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -AsSecureString; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd); [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
echo %pwd:^=^^%>>login.txt
Glad to hear it, @user78873.
– mklement0
Apr 10 at 13:38
add a comment |
! characters disappearing is unrelated to PowerShell - it suggests that cmd.exe's enabledelayedexpansion option is in effect, in which case ! serves as a variable-name delimiter - and in which case isolated ! chars. are simply discarded.
As an aside: ! is therefore not an escape character.
You therefore need to:
Disable delayed variable expansion with
setLocal disabledelayedexpansion:- Note that delayed expansion is off by default, so something in your environment must have turned it on.
Additionally, as Squashman points out,
^characters -cmd.exe's escape char. in unquoted strings - would be "eaten", so you must escape all^chars. as^^, which can you do with%pwd:^=^^%.
To put it all together:
@echo off
setLocal disabledelayedexpansion
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -AsSecureString; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd); [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
echo %pwd:^=^^%>>login.txt
! characters disappearing is unrelated to PowerShell - it suggests that cmd.exe's enabledelayedexpansion option is in effect, in which case ! serves as a variable-name delimiter - and in which case isolated ! chars. are simply discarded.
As an aside: ! is therefore not an escape character.
You therefore need to:
Disable delayed variable expansion with
setLocal disabledelayedexpansion:- Note that delayed expansion is off by default, so something in your environment must have turned it on.
Additionally, as Squashman points out,
^characters -cmd.exe's escape char. in unquoted strings - would be "eaten", so you must escape all^chars. as^^, which can you do with%pwd:^=^^%.
To put it all together:
@echo off
setLocal disabledelayedexpansion
set "psCmd=powershell -Command "$pwd = read-host 'Enter Your Password' -AsSecureString; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd); [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /F "usebackq delims=" %%# in (`%psCmd%`) do set "pwd=%%#"
echo %pwd:^=^^%>>login.txt
edited Mar 26 at 20:37
answered Mar 26 at 20:21
mklement0mklement0
151k25 gold badges272 silver badges311 bronze badges
151k25 gold badges272 silver badges311 bronze badges
Glad to hear it, @user78873.
– mklement0
Apr 10 at 13:38
add a comment |
Glad to hear it, @user78873.
– mklement0
Apr 10 at 13:38
Glad to hear it, @user78873.
– mklement0
Apr 10 at 13:38
Glad to hear it, @user78873.
– mklement0
Apr 10 at 13:38
add a comment |
To convert this to PowerShell, you have most of the code already written:
$pwd = Read-Host 'Enter Your Password' -AsSecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) | Add-Content -Path login.txt
add a comment |
To convert this to PowerShell, you have most of the code already written:
$pwd = Read-Host 'Enter Your Password' -AsSecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) | Add-Content -Path login.txt
add a comment |
To convert this to PowerShell, you have most of the code already written:
$pwd = Read-Host 'Enter Your Password' -AsSecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) | Add-Content -Path login.txt
To convert this to PowerShell, you have most of the code already written:
$pwd = Read-Host 'Enter Your Password' -AsSecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) | Add-Content -Path login.txt
answered Mar 26 at 20:05
AdminOfThingsAdminOfThings
5,7902 gold badges2 silver badges14 bronze badges
5,7902 gold badges2 silver badges14 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365022%2fhide-password-typed-in-console-batch-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
I recommend doing this entirely in Powershell.
– UnhandledExcepSean
Mar 26 at 19:51
Can you tell me how to do it
– user78873
Mar 26 at 19:57
Possible duplicate of Batch File Command Hide Password
– Squashman
Mar 26 at 20:11
You are missing some stuff in your code. The reason the
^does not get written tologin.txtis because the variable is expanded before execution and assumes you want to use the^as an escape character. You either need to escape the escape with string substitution or output the variable with delayed expansion.– Squashman
Mar 26 at 20:15
1
@mklement0, you are probably correct. I kept focusing on what the user was writing because they kept saying ESCAPE. The exclamation is not an escape.
– Squashman
Mar 26 at 20:37