Enter user and password in bat file

Asked

Viewed 6,742 times

1

I have a. bat file that automatically copies files from one server to another. We are updating the environment and this server will be modified and when testing . bat I received the following error:

Falha de logon: nome de usuário desconhecido ou senha incorreta.

There is how to pass user and password in a command like the below?

@echo INICIO VENDAS
@echo.

copy \\192.168.203.130\ebsout\*.txt c:\wamp\www\SIG\ /y
  • Have you ever tried something like NET USE X: \\IP do Servidor\PASTA senha /USER:usuario /PERSISTENT:NO?

  • @diegofm tested this command and gave the error: "The specified network password is not correct", even though the password is correct. I’ll try to download both servers to see what happens.

1 answer

1

Considering that the system may be wanting to use its logged-in user in the authentication of the command, I can suggest that you try 1x using the password of the logged-in user, not the one you intend to use in the command, if you confirm what I understand, is below a suggestion as an alternative to try to circumvent this event:

É possível usando o SendKey (VBS) para enviar os dados de entrada

Abaixo um exemplo usando telnet com inserção de dados


inserir a descrição da imagem aqui


Only replace on the lines below the respective values to the variables:

[_usuario_] [_senha_] [_cmd_]

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

set "_cmd_=copy 192.168.203.130 ebsout*. txt c: wamp www SIG /y"

@echo off & setlocal enabledelayedexpansion & mode 60,20 & color 9F

echo/INICIO VENDAS & echo/ & mode con cols=77 lines=30

set "_usuario_=cisco_user" & set "_senha_=4LoCk007XSwT001"
set "_cmd_=telnet.exe 192.168.0.254"

>"%temp%\_temp_file_4vbs_.vbs"^
    (
     echo/ Set WshShell = WScript.CreateObject^("WScript.Shell"^)
     echo/ Set objShell = WScript.CreateObject^("WScript.Shell"^)
     echo/ StrPwd  = "!_senha_!"
     echo/ StrUser = "!_usuario_!"
     echo/ for i=1 To Len^(StrUser^)
     echo/     x = Mid^(StrUser,i,1^)
     echo/     WshShell.SendKeys x
     echo/     Wscript.Sleep 250
     echo/ Next
     echo/ Wscript.Sleep 500
     echo/ WshShell.SendKeys "({ENTER})"
     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 "dir"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "exit"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     echo/ Wscript.Sleep 200
     echo/ WshShell.SendKeys "({ENTER})"
     ) 

set "_temp_vbs=%temp%\_temp_file_4vbs_.vbs" &  start "" /b !_cmd_!
@"%Windir%\System32\cScript.exe" //nologo "!_temp_vbs!" <nul & del /q /f "!_temp_vbs!" & goto :eof



Browser other questions tagged

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