0

I would like to write while executing a bat file.

I have to type user and password after executing a command. When executing the command I have the following output:

You have been directed successfully.

Usernae =

After the user enters the username manually it asks for the password.

You have been directed successfully.

Usernae = user

password =

How can I create a batch script to write this user and password without being asked to type?

Beto
  • 579
  • 1
  • 5
  • 15
  • You can put username in a file and redirect it to standard input. [read more](http://www.ustrem.org/en/articles/redirecting-input-output-streams-en/), Heredocs are the other solution ([more details ...](https://stackoverflow.com/questions/1015163/heredoc-for-windows-batch)). – M.Fooladgar Apr 03 '19 at 12:48
  • 1
    `(echo user&echo secret)|application.exe` might work (depends on how the application is programmed). – Stephan Apr 03 '19 at 12:57
  • 1
    Please search the site before asking questions, I'm relatively confident that questions which involve inputting names and passwords are asked several times every week. – Compo Apr 03 '19 at 13:06
  • So, I agreed with @Stephan because I have some many software particularly developed in FORTRAN and they don’t accept arguments and others things like this in script bat. – Io-oI Apr 04 '19 at 00:34

1 Answers1

1

You can use SendKey in VBS to send this input.


Just replace the placeholder values in the following code with the actual values:

set "_user_=user-x" & set "_pwd_=password-y"

set "_exec_=drive:\path\to\your\executable.exe"
@echo off & setlocal enabledelayedexpansion & cls

mode con cols=70 lines=20 & color 9F

set "_user_=user-x" & set "_pwd_=password-y" 

set "_exec_=drive:\path\to\your\executable.exe"

>"%temp%\_temp_file_4vbs_.vbs"^
    (
     echo/ Set WshShell = WScript.CreateObject^("WScript.Shell"^)
     echo/ Set objShell = WScript.CreateObject^("WScript.Shell"^)
     echo/ StrUser  = "!_user_!"
     echo/ StrPwd  = "!_pwd_!"
     echo/ Wscript.Sleep 1000
     echo/     Wscript.Sleep 1000
     echo/ for h=1 To Len^(StrUser^)
     echo/     x = Mid^(StrUser,h,1^)
     echo/     WshShell.SendKeys x
     echo/     Wscript.Sleep 200
     echo/ Next
     echo/     Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     echo/ Wscript.Sleep 200
     echo/ for j=1 To Len^(StrPwd^)
     echo/     x = Mid^(StrPwd,j,1^)
     echo/     WshShell.SendKeys x
     echo/     Wscript.Sleep 200
     echo/ Next 
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
    ) 

set "_temp_vbs=%temp%\_temp_file_4vbs_.vbs" & cls && start "" /b "!_exec_!"

@"%Windir%\System32\cScript.exe" //nologo "!_temp_vbs!" & del /q /f "!_temp_vbs!" & goto :eof
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Io-oI
  • 2,514
  • 3
  • 22
  • 29
  • The script on this **.gif** are using one FORTRAN software that don’t use or accept any code (available by google search or in **SO**) to receive any argument. – Io-oI Apr 05 '19 at 00:03