How to enter data at runtime?

Asked

Viewed 597 times

1

I would like to write while running a bat file.

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

Você foi direcionado com sucesso.

Usernae = 

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

Você foi direcionado com sucesso.

Usernae = usuario

password = 

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

  • You have no way to interact with the terminal by direct script... What I think would be the solution is to check if there is a way to pass a parameter to this your script that you are running that is the user and the password. More or less like Mysql does in its CLI with -u and -p

  • Since you don’t want to type, the user and password values of your script would be static?

  • @Andréfilipe, at first yes.

2 answers

1


I have some programs that we use developed in FORTRAN, and we don’t have the codes, and they only receive the input data via typing.

Since there was no way to automate data receipt (we used many methods suggested in the first editions of this reply), the solution was to use the VBS to simulate the typing:

• Usando o VBS processando os dados de entrada num exemplo com 4 inputs: • malha.dad, malha.log, n, n!

inserir a descrição da imagem aqui


• To port this code to your scenario, only replace on the lines below the respective values to the variables:

[_usuario_] [_senha_] [_exec_]

set "_usuario_=user-x" & set "_password_=password-y"

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

@echo off & setlocal enabledelayedexpansion & cls

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

set "_usuario_=usuario-x" & set "_senha_=senha-y" 

set "_exec_=drive:\caminho\do\seu\executavel.exe"

>"%temp%\_temp_file_4vbs_.vbs"^
    (
     echo/ Set WshShell = WScript.CreateObject^("WScript.Shell"^)
     echo/ Set objShell = WScript.CreateObject^("WScript.Shell"^)
     echo/ StrUser  = "!_usuario_!"
     echo/ StrPwd  = "!_senha_!"
     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
  • Unfortunately these commands did not serve me. I need a way to send this to the program without having to type and I can’t change the program because it’s a third-party executable.

  • @Good afternoon, I changed everything in the answer, now using bat with VBS, and has also been tested with program that requests input data...

0

You can redirect the input of a file.

Password file.cmd

@echo off

echo Lendo senha...
set /p senha=< senha.txt
echo Senha digitada: [%senha%]

Password file.txt

123

Whirling:

c:...> senha.cmd
Lendo senha...
Senha digitada: [123]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.