What is myscript.exe? Is it really a script? Powershell? VB script? Or is it a compiled executable?
You can try piping stdin to the program.
echo MyPassword | myscript.exe
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
Below is my command to perform one activity. It accepts few arguments which is fine and no issues there. But when we run that command in cmd, it asks for password and confirm password.
I want to automate that password and confirm password part. How can I do that?
Example:
When we run below command in cmd -
c:\Test\myscript.exe --arg1 --arg2 --config "c:\Temp\config.cfg" --confirm
It shows below in same command prompt-
Performing the script execution for ABCD.
Enter password:
Type again to confirm:
What I need is, How can I automate this entering of password and confirm password, considering I have the password.
Please help here. Powershell or vbscript solution is preferred.
What is myscript.exe? Is it really a script? Powershell? VB script? Or is it a compiled executable?
You can try piping stdin to the program.
echo MyPassword | myscript.exe
Hello,
Consider Myscript.exe as any third party software and we cannot alter or modify it. The exe has fixed arguments which it takes as an input but not the password by default. below powershell link has similar solution but I am not able to make it. Could you please help me here. Please let me know if any further details are needed here. Just check the last script of below link. Something similar I needed.
Hence echo will not work here.
What I actually need is to automate password input for any application/exe via cmd or powershell prompt. something related to New-Object System.Diagnostics.Process
should work.
how-to-provide-input-for-prompts-
Please check the very last script of above link. similar I need to implement.
Here is a Powershell script to use nslookup to query a name. Do you need to look for a specific response? That last script that you pointed out should work.
$MyProcess = New-Object System.Diagnostics.Process
$MyProcess.StartInfo.FileName = "nslookup.exe"
$MyProcess.StartInfo.Arguments = "-"
$MyProcess.StartInfo.UseShellExecute = $false
$MyProcess.StartInfo.RedirectStandardInput = $true
$MyProcess.StartInfo.RedirectStandardOutput = $true
$MyProcess.StartInfo.RedirectStandardError = $true
$MyProcess.Start()
$StdIn = $MyProcess.StandardInput
$StdIn.WriteLine("yahoo.com")
$StdIn.WriteLine("exit")
$StdIn.Close()
$MyProcess.WaitForExit()
$MyProcess.StandardOutput.ReadToEnd()
$MyProcess.StandardError.ReadToEnd()
I played around some more with calling nslookup and netsh to see if I could simulate a password prompt. I had mixed results. When nslookup outputs a ">", a .readline call will hang on that. I can do a .read to get each character, but once .peek returns a -1, then I have to do a .readline to reset it, otherwise it appears that it will always return a -1 even if more characters are available to be read.
You will just have to test "MyScript.exe" to see how it interacts with console input/ouput.
Function GetResponse {
Start-Sleep -Milliseconds 1000 # give the proram some time to run
$buffer = $stdout.readline() # Assume the we have at least one line of output
while ($StdOut.peek() -ne -1) {
$buffer += [char]$StdOut.read() # read char by char because readline might hang
}
return $buffer
}
$MyProcess = New-Object System.Diagnostics.Process
$MyProcess.StartInfo.FileName = "nslookup.exe"
$MyProcess.StartInfo.Arguments = "-"
$MyProcess.StartInfo.UseShellExecute = $false
$MyProcess.StartInfo.RedirectStandardInput = $true
$MyProcess.StartInfo.RedirectStandardOutput = $true
$MyProcess.StartInfo.RedirectStandardError = $true
$MyProcess.Start()
$StdIn = $MyProcess.StandardInput
$StdOut = $MyProcess.StandardOutput
$StdErr = $MyProcess.StandardError
cls
"---------------Initial prompt-------------"
GetResponse
"---------------yahoo-------------"
$StdIn.WriteLine("yahoo.com")
GetResponse
"---------------msn-------------"
$StdIn.WriteLine("msn.com")
GetResponse
"---------------exit-------------"
$StdIn.WriteLine("exit")
GetResponse
while ($MyProcess.HasExited -ne $true) { Start-Sleep -Milliseconds 50 }
"Final Stdout-------------"
$StdOut.ReadToEnd()
"Final Stderr-------------"
$StdErr.ReadToEnd()
return
Thanks MotoX80 for your response. Unfortunately above script is not working as expected. Above you assume we will enter the password manually but actually we will pass the password as a parameter to powershell script and from there it will read that password and enter the password automatically whenever it prompts for passwords two time. I did not understand the role of GetResponse function in this case.